2019-2020 DIS Grade 11 Computer Department Python Code Assignment

Verified

Added on  2022/07/28

|4
|388
|28
Homework Assignment
AI Summary
This document presents a solved Python assignment for a Grade 11 Computer Science course. The assignment focuses on core programming concepts such as loops (both 'for' and 'while' loops), conditional statements ('if', 'else'), and input/output operations. The solutions include code snippets that demonstrate how to display even numbers, print a name multiple times, determine the length of a string, and generate random numbers. The assignment covers fundamental programming skills and provides practical examples of how to implement these concepts in Python. Students can use this solution to understand how to approach similar programming problems and learn the practical application of these concepts. The assignment showcases the use of loops, conditional statements, and other programming concepts. The document is provided by a student and available on Desklib, a platform which provides AI based study tools for students to help with their assignments.
Document Page
DIS 2019-2020 Grade 11
Computer Department Online Assignment #4 Term 2
Name: ______________________________________ Due Date: April 19, 2020
Objectives: Students should be able to:
1. Know how to apply loops.
2. Print an output many times.
3. Draw flowcharts
Q1) Write the Python code that takes a value from an input and check:
a. If the value entered is “even” show even number from 2 till 8 using for
loop.
b. Else if the value entered is “name” print your name and age 3 times using
while loop.
c. Else show the value entered in the input.
Answer Flowchart
value = input("Enter a value: ")
if(value == "even"):
for x in range(1, 10):
if(x % 2 == 0):
print(x)
elif(value == "name"):
x = 0
while (x < 3):
print("My Name: John
Doe")
print("Age: 20")
x=x+1
else:
print(value)
Page 1 of 4
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
DIS 2019-2020 Grade 11
Computer Department Online Assignment #4 Term 2
Q2) Write the Python code that shows the following output using for and while
loop.
Page 2 of 4
Document Page
DIS 2019-2020 Grade 11
Computer Department Online Assignment #4 Term 2
Q3) Write the Python code the takes a string value from an input and check:
a. If the length of the value entered is even, show “even”
b. Else show “odd”
Research 😊
Page 3 of 4
While Loop For Loop Outp
ut
x = 0
while(x <= 10):
print(x * x)
x = x + 1
for x in range(0, 10):
print(x * x)
0
1
4
9
16
25
36
49
64
81
100
Answer
value = input("Enter a value:")
if(len(value) % 2 == 0):
print("Even")
else:
print("odd")
Document Page
DIS 2019-2020 Grade 11
Computer Department Online Assignment #4 Term 2
Q4) Write the python code that shows a random value between 1 and 10, five
times using for loop.
Answer
import random
for x in range(5):
print(random.randint(0,9))
Page 4 of 4
chevron_up_icon
1 out of 4
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]