Revision Midterm Questions
Revision Midterm Questions
1) sum of even numbers greater than 15. User enters ‘q’ to quit.
2) sum=0
3) while True:
4) n=input("Enter a number (or q to quit):")
5) if n=="q":
6) break
7) n=int(n)
8) if n>15 and n%2==0:
9) sum+=n
10) print("Sum of even numbers greater than 15 is {}".format(sum))
11) count of even numbers. User enters ‘q’ to quit.
12) count=0
13) while True:
14) n=input("Enter a number (or q to quit):")
15) if n=="q":
16) break
17) n=int(n)
18) if n%2==0:
19) count+=1
20) print("Count of even numbers is {}".format(count))
3)start end numbers are specified to get an equation as given below
Start : 2
End: 5
2*2= 4
3*3= 9
4*4=16
5*5=25
- def num(start,end):
- for i in range(start,end+1):
- print("{0} * {1} = {2}".format(i,i,i*i))
- start=2
- end=5
- num(start,end)
-
4)loop ends when user enters the letter 'q' ( use while :True )
while True:
n=input("Enter integer (or q to break):")
if n=="q":
break
5) Loop stops only when user enters a positive number or zero ( use while :True )
while True:
n=int(input("Enter integer (or q to break):"))
if n==0 or n%2==0:
break
* *
* * *
* * * *
* * * * *
- for i in range(0,5):
for j in range(0,i+1):
print("*", end=" ")
print("\n")
7)Write a function that will interact with the user to accept n numbers and returns the largest and
the smallest value ( do not use inbuild functions min and max)
8)Write a program that will accept 5 marks for the subject and to display the grade for each ina
table format using the grade function covered in class ( use loop and function)
Enter mark 1: 12
Enter mark 2: 56
Enter mark 3: 67
Enter mark 4: 89
Enter mark 5: 89
Mark: Grade:
12 D
56 C
67 B
89 A
89 A
9)Trace the below program .consider variable i,j, start number,and output as given in the excel
sheet.