1.
FirstNumber = int (0)
SecondNumber = int (0)
Sum = int (0)
FirstNumber = int (input( "Enter First Whole Number: "))
SecondNumber = int (input( "Enter Second Whole Number: "))
Sum = FirstNumber + SecondNumber
print ("The sum equals ", Sum)
2.
FirstNumber = int (0)
SecondNumber = int (0)
Sum = int (0)
FirstNumber = int(input( "Enter First Whole Number: "))
SecondNumber = int (input( "Enter Second Whole Number: "))
if FirstNumber > SecondNumber:
print ("First Whole Number is largest ", FirstNumber)
else:
print ("Second Whole Number is largest ", SecondNumber)
3.
Number = int (12)
Highest = int (101)
if Number > Highest:
Highest = Number
print ('A bigger number has been found ', Number)
4.
for Counter in range (1, 6):
print ('*', end = '')
5.
NewValue = float(input('Please enter a negative number '))
while NewValue >= 0:
NewValue = float(input('Please enter a NEGATIVE number '))
6.
Number = int (0)
Count = int (0)
Sum = int (0)
while Count < 5:
Number = int(input( "Enter a Whole Number: "))
Sum = Sum + Number
Count = Count + 1
print ("Sum of five numbers is ", Sum)
7.
Number = int (0)
Count = int (0)
Sum = int (0)
for Count in range (1, 6):
Number = int(input( "Enter a Whole Number: "))
Sum = Sum + Number
print ("Sum of five numbers is ", Sum)
8.
NumberOfTickets = int (0)
Discount = float (0)
Cost = float(0)
while NumberOfTickets < 1 or NumberOfTickets > 25:
NumberOfTickets = float(input ('How many tickets to buy? '))
Discount = 0.2
if NumberOfTickets < 10:
Discount = 0
elif NumberOfTickets < 20:
Discount = 0.1
Cost = NumberOfTickets * 20 * (1 - Discount)
print ('Your tickets cost', Cost)
9.
Maths = int (0)
MathsHighest = int (0)
MathsLowest = int (100)
MathsTotal = int (0)
Science = int (0)
ScienceHighest = int (0)
ScienceLowest = int (100)
ScienceTotal = int (0)
English = int (0)
EnglishHighest = int (0)
EnglishLowest = int (100)
EnglishTotal = int (0)
IT = int (0)
ITHighest = int (0)
ITLowest = int (100)
ITTotal = int (0)
OverallHighest = int(0)
OverallLowest = int(100)
OverallTotal = int(0)
Student = int (3)
Count = int (0)
for Count in range (1, Student + 1):
Maths = int(input( "Enter a Mark for Maths "))
if MathsLowest > Maths:
MathsLowest = Maths
if MathsHighest < Maths:
MathsHighest = Maths
MathsTotal = MathsTotal + Maths
if OverallLowest > Maths:
OverallLowest = Maths
if OverallHighest < Maths:
OverallHighest = Maths
OverallTotal = OverallTotal + Maths
English = int(input( "Enter a Mark for English "))
if EnglishLowest > English:
EnglishLowest = English
if EnglishHighest < English:
EnglishHighest = English
EnglishTotal = EnglishTotal + English
if OverallLowest > English:
OverallLowest = English
if OverallHighest < English:
OverallHighest = English
OverallTotal = OverallTotal + English
Science = int(input( "Enter a Mark for Science "))
if ScienceLowest > Science:
ScienceLowest = Science
if ScienceHighest < Science:
ScienceHighest = Science
ScienceTotal = ScienceTotal + Science
if OverallLowest > Science:
OverallLowest = Science
if OverallHighest < Science:
OverallHighest = Science
OverallTotal = OverallTotal + Science
IT = int(input( "Enter a Mark for IT "))
if ITLowest > IT:
ITLowest = IT
if ITHighest < IT:
ITHighest = IT
ITTotal = ITTotal + IT
if OverallLowest > IT:
OverallLowest = IT
if OverallHighest < IT:
OverallHighest = IT
OverallTotal = OverallTotal + IT
print ("Highest mark for Maths is ", MathsHighest)
print ("Lowest mark for Maths is ", MathsLowest)
MathsAverage = float(MathsTotal/Student)
print ("Average mark for Maths is ", MathsAverage)
print ("Highest mark for English is ", EnglishHighest)
print ("Lowest mark for English is ", EnglishLowest)
EnglishAverage = float(EnglishTotal/Student)
print ("Average mark for English is ", EnglishAverage)
print ("Highest mark for Science is ", ScienceHighest)
print ("Lowest mark for Science is ", ScienceLowest)
ScienceAverage = float(ScienceTotal/Student)
print ("Average mark for Science is ", ScienceAverage)
print ("Highest mark for IT is ", ITHighest)
print ("Lowest mark for IT is ", ITLowest)
ITAverage = float(ITTotal/Student)
print ("Average mark for IT is ", ITAverage)
print ("Highest mark overall is ", OverallHighest)
print ("Lowest mark overall is ", OverallLowest)
OverallAverage = float(OverallTotal/(Student * 4))
print ("Average mark overall is ", OverallAverage)
10. 例子的另一种实现方法
OverallHighest = 0
OverallLowest = 100
OverallTotal = 0
Mark = 0
#for n in range(1,4):
# print(n)
for Test in range(1, 5):
SubjectHighest = 0
SubjectLowest = 100
SubjectTotal = 0
if( Test ==1 ):
SubjectName ="Maths"
if( Test == 2 ):
SubjectName ="Science"
if( Test == 3 ):
SubjectName ="English"
if( Test == 4 ):
SubjectName ="IT"
for StudentNumber in range( 1, 4):
print("Enter Student", StudentNumber,"‘s mark for",SubjectName)
Mark = int(input ())
if(Mark < 101 and Mark > -1):
if (Mark < OverallLowest):
OverallLowest = Mark
if (Mark < SubjectLowest):
SubjectLowest = Mark
if (Mark > OverallHighest):
OverallHighest = Mark
if (Mark > SubjectHighest):
SubjectHighest = Mark
OverallTotal = OverallTotal + Mark
SubjectTotal = SubjectTotal + Mark
SubjectAverage = SubjectTotal/3
print (SubjectName)
print ("Average is", SubjectAverage)
print ("Highest Mark is", SubjectHighest)
print ("Lowest Mark is", SubjectLowest)
OverallAverage = OverallTotal/12
print ("Overall Average is", OverallAverage)
print ("Overall Highest Mark is", OverallHighest)
print ("Overall Lowest Mark is", OverallLowest)
其他的一些例子::::
11.
grade = 111
if grade == 'A':
print("Excellent")
elif grade == 'B':
print("Good")
elif grade == 'C':
print("Average")
else:
print("XXXX")
12.
Cost = 10**3 ##^
Price = Cost *2
Tax = Price*0.12
print(Cost,Price,Tax)
SellingPrice = Price + Tax
print(SellingPrice)
Gender = 'M '+'hello'
Chosen = False #boolean zheshiyigezhushi
print(Gender,Chosen)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)