Python
Python
1-Write a for loop that will iterate from 0 to 20. For each iteration, it
will check if the current number is even or odd, and report that to the
screen (e.g. "2 is even").
if num %2== 0:
print(num,'is even')
else:
print(num,'is odd'
Solution:
first way:
if num % 2 == 1:
print (num)
Second way:
if num % 2 == 0:
continue
print (num)
1
3. Write a Python program to calculate area or circumference of
a circle.
Solution:
pi = 3.14
if(u == "A"):
area = pi * r * r
) elif (u == "C"):
circ = 2 * pi * r
Solution:
prod = 1
for i in mylist :
prod = prod * i
print ( prod )
2
5. Write a Python program to get the sum of even numbers from 1
to 100.
Solution:
sum = 0
if(i % 2 == 0):
sum = sum +
i print (sum)
print('welcom')
else:
print('wrong')
3
8. Create a user login page that prompts for password and it allow four attempts
for incorrect.
tries=4
mainpassword='Ahmed'
while user_pass!=mainpassword:
tries=tries-1
print('wrong pass')
if tries==0:
break
else:
print('correct pass')
product=i*j
print(i,'*',j,'=',product)
if num %5== 0:
print(num)
4
11. Loop through the range(1,20) :
(a)
if x== 10:
continue
print(x)
(b)
print(x)
if x== 10:
break
12. Create a mixed list (containing string, number and a list). Print the
list
5
15. Implement a program that requests the student's degree in the course and determines
the student's grade whether it is A, B, C, or F
16. The student is considered successful in the course if he attends more than 70% of
the classes and obtains more than 40 marks on the final exam. Determine whether
the student is successful or not.