0% found this document useful (0 votes)
10 views1 page

Sample Code

The document presents a Python program that allows users to choose from three options: calculating average marks, calculating the area of a right-angled triangle, or generating odd numbers from 0 to 10. It includes input validation and categorizes average marks into distinction, credit, pass, or fail. The program runs in a loop until a valid option is selected and executed.

Uploaded by

okellosteven1234
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views1 page

Sample Code

The document presents a Python program that allows users to choose from three options: calculating average marks, calculating the area of a right-angled triangle, or generating odd numbers from 0 to 10. It includes input validation and categorizes average marks into distinction, credit, pass, or fail. The program runs in a loop until a valid option is selected and executed.

Uploaded by

okellosteven1234
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Application of if, loop and logical operators, list

while True:
print("Select an option:")
print("1. Calculate Average Marks")
print("2. Calculate area of right angled triangle")
print("3. Generate Odd numbers from 0 t0 10")
print("------------")
choice = int(input("Enter your choice: "))
if choice == 1:
subject1=int(input("Enter marks for subject 1: "))
subject2=int(input("Enter marks for subject 2: "))
subject3=int(input("Enter marks for subject 3: "))
subject4=int(input("Enter marks for subject 4: "))
subject5=int(input("Enter marks for subject 5: "))
subject6=int(input("Enter marks for subject 6: "))
sub_list=[subject1,subject2,subject3,subject4,subject5,subject6]
total_marks=sum(sub_list)
average_marks=total_marks/len(sub_list)
print("Average= ",average_marks)
if average_marks >100 and average_marks <0:
print("Enter valid marks")

elif average_marks >= 80 and average_marks <= 100:


print("You have Distinction")
elif average_marks >= 60 and average_marks <80:
print("You have Credit")
elif average_marks >=40 and average_marks <60:
print("You have Pass")
else:
print("You have Fail")
break
elif choice == 2:
base=float(input("Enter the base: "))
height=float(input("Enter the height: "))
area=0.5*base*height
print("The area of the right angled triangle is ",area)
break
elif choice == 3:
x=0
while x<=10:
if x%2==1:
print(x)
x=x+1
break
else:
print("Enter a valid option")
print("------------")

You might also like