Assignment 1: Calculator:
Please enter two numbers and a symbol to complete + - * /% / / of the two numbers**
while True: p=input("Do you want to continue using the calculator? ( y/n)") if p == 'y': a = float(input("Enter number 1:")) b = float(input("Enter number 2:")) c = str(input("Input algorithm:")) if c == "+": z = a + b print("%s And %s The sum of is%s"%(a,b,z)) elif c == "-": z = a - b print("%s And %s The difference is%s"%(a,b,z)) elif c == "*": z = a * b print("%s And %s Product of%s"%(a,b,z)) elif c == "/": z = a / b print("%s And %s Quotient of%s"%(a,b,z)) elif c == "%": z = a % b print("%s And %s The remainder of the quotient is%s"%(a,b,z)) elif c == "//": z = a // b print("%s And %s The integer bit value of the quotient is%s"%(a,b,z)) elif c == "**": z = a ** b print("%s of %s Power is%s"%(a,b,z)) elif p == 'n': break else: print("Incorrect input")
Assignment 2: design a program to complete the purchase of (hero) goods
Display commodity information (discount) - > enter commodity price - > Enter purchase quantity - > prompt for payment
Enter payment amount - > Print purchase receipt (extension)
while True: print("\n\t\t\t Hero mall list\n") print("~ *"*30) print("\n Number name nickname price inventory description\n") print(" 1 NAR lost teeth 3500 100 jungle will not forgive blindness and ignorance\n") print(" 2 Ruiwen exile blade 4000 100 she is a cruel and efficient soldier\n") print(" 3 Wayne night hunter 3500 100 the world is not as beautiful as people think\n") print(" 4 Zach biochemical demon 3000 100 even if you don't have a spine, you have to stand up\n") print(" 5 Jess future Guardian 2500 100 is armed with wisdom and charm. Your choice is not wrong\n") print("~ *"*30) choice = input("\n(reminder)Please enter the hero number you want to buy:") if choice == "1": print("~ *"*30) print("\n\t Hero name: NAR(epic)\n") print("\t Hero attribute: HP 428(+85)/Energy value 200(+0)/Movement speed 425/Attack power 55.8(+3.2)\n\t\t Attack speed 0.651(+3.1%)/Armor value 24(+1.25)/Attack range 125\n") print("\n\t Hero's motto: the jungle will not forgive blindness and ignorance\n") print("\t Lucky Summoner discount 1.0 Discount, 350\n") a = int(input("Please enter purchase quantity:")) b = 350 * a if a > 100: print("Sorry, the maximum purchase is 100, please re-enter") else: print("\n The amount you need to pay is%s\n"%b) c = int (input("Please pay the amount required for the goods:")) if b==c : print("\n\t Payment successful\n") print("\n Printing ticket, please wait......\n") else: print("\n Wrong payment amount, please pay again\n") elif choice == "2": print("~ *"*30) print("\n\t Hero name: Ruiwen(legend)\n") print("\t Hero attribute: HP 428(+85)/Energy value 200(+0)/Movement speed 425/Attack power 55.8(+3.2)\n\t\t Attack speed 0.651(+3.1%)/Armor value 24(+1.25)/Attack range 125\n") print("\n\t Hero motto: she is a cruel and efficient soldier\n") print("\t Lucky Summoner discount 1.0 Discount, need to pay 400\n") a1 = int(input("Please enter purchase quantity:")) b1 = 400 * a1 if a1 > 100: print("Sorry, the maximum purchase is 100, please re-enter") else: print("\n The amount you need to pay is%s\n"%b1) c1 = int(input("Please pay the amount required for the goods:")) if b1==c1: print("\n\t Payment successful\n") print("\n Printing ticket, please wait......\n") else: print("\n Wrong payment amount, please pay again\n") elif choice == "3": print("~ *"*30) print("\n\t Hero name: Wayne(epic)\n") print("\t Hero attribute: HP 428(+85)/Energy value 200(+0)/Movement speed 425/Attack power 55.8(+3.2)\n\t\t Attack speed 0.651(+3.1%)/Armor value 24(+1.25)/Attack range 125\n") print("\n\t Hero motto: the world is not as beautiful as people think\n") print("\t Lucky Summoner discount 1.0 Discount, 350\n") a2 = int(input("Please enter purchase quantity:")) b2 = 350 * a2 if a2 > 100: print("Sorry, the maximum purchase is 100, please re-enter") else: print("\n The amount you need to pay is%s\n"%b2) c2 = int(input("Please pay the amount required for the goods:")) if b2==c2: print("\n\t Payment successful\n") print("\n Printing ticket, please wait......\n") else: print("\n Wrong payment amount, please pay again\n") elif choice == "4": print("~ *"*30) print("\n\t Hero name: Zach(epic)\n") print("\t Hero attribute: HP 428(+85)/Energy value 200(+0)/Movement speed 425/Attack power 55.8(+3.2)\n\t\t Attack speed 0.651(+3.1%)/Armor value 24(+1.25)/Attack range 125\n") print("\n\t Hero motto: even if you don't have a spine, you must stand up\n") print("\t Lucky Summoner discount 1.0 Discount, 350\n") a3 = int(input("Please enter purchase quantity:")) b3 = 350 * a3 if a3 > 100: print("Sorry, the maximum purchase is 100, please re-enter") else: print("\n The amount you need to pay is%s\n"%b3) c3 = int(input("Please pay the amount required for the goods:")) if b3==c3: print("\n\t Payment successful\n") print("\n Printing ticket, please wait......\n") else: print("\n Wrong payment amount, please pay again\n") elif choice == "5": print("~ *"*30) print("\n\t Hero name: Jess(ordinary)\n") print("\t Hero attribute: HP 428(+85)/Energy value 200(+0)/Movement speed 425/Attack power 55.8(+3.2)\n\t\t Attack speed 0.651(+3.1%)/Armor value 24(+1.25)/Attack range 125\n") print("\n\t Hero motto: armed with wisdom and charm, your choice is not wrong\n") print("\t Lucky Summoner discount 1.0 Discount, 250\n") a4 = int(input("Please enter purchase quantity:")) b4 = 250 * a4 if a4 > 100: print("Sorry, the maximum purchase is 100, please re-enter") else: print("\n The amount you need to pay is%s\n"%b4) c4 = int(input("Please pay the amount required for the goods:")) if b4==c4: print("\n\t Payment successful\n") print("\n Printing ticket, please wait......\n") else: print("\n Wrong payment amount, please pay again\n") else: break
Assignment 3:
Health plan
User input height (m), weight (kg)
Calculation formula: BMI = weight / height^2 BMI < 18.5:Too light 18.5≤ BMI <24:normal 24 ≤ BMI <27:overweight 27 ≤ BMI < 30:Mild obesity 30 ≤ BMI < 35:Moderate obesity BMI ≥ 35:Severe obesity
while True: height = float(input('Please enter your height(m):')) weight = float(input('Please enter your weight(kg):')) BML = (weight / (height**2)) print('BML = weight / height^2') print(f'Yours BML = {BML}') if (BML <= 100 and BML >= 0): if (BML < 18.5): print('Too light!') elif(BML < 24): print('Normal weight.') elif(BML < 27): print('Overweight!') elif(BML < 30): print('Mild obesity.') elif(BML < 35): print('Moderate obesity.') else: print('Severe obesity.') else: print('The data you entered is incorrect!')
Job 4:
*
**
***
****
*****
******
layer = int(input("Please enter the number of layers to print")) index = 1 while index <= layer: index2 = 1 while index2 <= index: print("*",end="") index2 += 1 print("") index += 1
Assignment 5:
Enter a number to determine whether the number is a prime number
num = int(input("Please enter a number")) index = 2 flag = True while index < (num //2): if num % index == 0: flag = False break index += 1 if flag == True: print("Is a prime number") else: print("Composite number")
Job 6:
Let the user enter a month to judge which season this month is? Suppose 3 to 3
April is spring, may to August is summer, September to October is autumn, November, December, January and February
Month is winter
month = int(input('Please enter a month:')) if month == 3 or month == 4: print(f'{month}June is spring') elif 5 <= month <= 8: print(f'{month}June is summer') elif 9 <= month <= 10: print(f'{month}September is autumn') elif 11 <= month <= 12 or 1 <= month <= 2: print(f'{month}Month is winter') else: print('Your input is incorrect!')
Job 7:
Prompt the user for the user name, and then prompt for the password. If the user name
If it is "admin" and the password is "88888", the prompt is correct. Otherwise, if
If the user name is not admin, you will be prompted that the user name does not exist. If the user name is
admin will prompt the password error.
user = input('Please enter your user name:') a = 'admin' b = '88888' if user == a: print('The user name is correct') passwd = (input('Please input a password:')) if passwd == b: print('Login succeeded!') else: print('Wrong password!') else: print('User name does not exist!')
Assignment 8: there are some four digits. The hundred digits are 3 and the ten digits are 6. They can be divided by both 2 and 3. What are the largest and smallest of these four digits?
index = 1000 while index < 10000: a = index // 100 % 10 b = index //10 % 10 if a == 3 and b ==6 and index % 2 == 0: print(index) index += 1
Assignment 9: program to find A four digit natural number ABCD, which is multiplied by A and becomes DCBA
a = input('Please enter a four digit number:') while a.isdigit(): b = int(a) break else: a = input('Please enter a four digit number:') a.isdigit() a4 = b // 1000 a3 = b // 100 - b // 1000 * 10 a2 = b // 10 -b //100 * 10 a1 = b - b // 10 * 10 print(str(a1)+str(a2)+str(a3)+str(a4))
Job 10: the user inputs two numbers a and b. If a can be divided by b or a plus b is greater than 1000, output a; otherwise, output b.
a = int(input('Please enter the first number:')) b = int(input('Please enter the second number:')) if a % b == 0 or a + b >= 1000: print(a) else: print(b) i += 1
Assignment 11: input Zhao Benshan's test results and display the awards
Score = = 100 points, dad bought him a car
Score > = 90 points, his mother bought him MP4
90 points > score > = 60 points. His mother bought him a reference book
Score < 60, don't buy anything
results = int(input('Please enter your academic record:')) if results > 100: print('Which one has more than 100 points') elif results == 100: print('Buy a car') elif results >= 90: print('buy MP4') elif results >= 60: print('Buy learning materials') elif 0 <= results < 60: print('Mixed doubles') else: print('There is no score below 0')
Assignment 12: Please enter a number to judge whether the number is even or odd. If an even number is used, please judge the multiples from 1 to 3. If it is odd, please judge the multiples from 1 to 5
undetermined
Assignment 13: enter the length of the three sides and calculate the area and perimeter of the triangle (Helen formula)
a = float(input("Please enter the first side length:")) b = float(input("Please enter the second side length:")) c = float(input("Please enter the third side length:")) while a + b <= c or a + c <= b or c + b <= a: print("The three sides you enter cannot form a triangle") a = float(input("Please enter the first side length:")) b = float(input("Please enter the second side length:")) c = float(input("Please enter the third side length:")) p = (a + b + c) / 2 area = (p*(p-a)*(p-b)*(p-c))**0.5 print("Area:%.2f"%area)
Assignment 14: the price of T-shirts in a store is 35 yuan / piece (10% off for 2 pieces and 20% off for more than 3 pieces), and the price of pants is 120 yuan / piece (10% off for more than 2 pieces). Xiaoming bought 3 T-shirts and 2 pairs of pants in the store. Please calculate and display how much Xiaoming should pay?
a=int(input("Please enter buy T Number of shirts:")) b=int(input("Please enter the number of pants to buy:")) if a==2: if b<2: sum1=(a*35)*0.9 sum2=b*120 sum3=sum1+sum2 print("Xiao Ming payable",sum3) else: sum1 = (a * 35) * 0.9 sum2 = (b * 120)*0.9 sum3 = sum1 + sum2 print("Xiao Ming payable", sum3) elif a>=3: if b<2: sum1=(a*35)*0.8 sum2=b*120 sum3=sum1+sum2 print("Xiao Ming payable",sum3) else: sum1 = (a * 35) * 0.8 sum2 = (b * 120)*0.9 sum3 = sum1 + sum2 print("Xiao Ming payable", sum3) elif a<2: if b<2: sum1=(a*35) sum2=b*120 sum3=sum1+sum2 print("Xiao Ming payable",sum3) else: sum1 = (a * 35) sum2 = (b * 120)*0.9 sum3 = sum1 + sum2 print("Xiao Ming payable", sum3)
Homework 15: chicken and rabbit are in the same cage. There are 35 heads from above and 94 feet from below. How many chickens and rabbits are there?
head = 35 foot = 94 #They are all rabbits y = (head * 4 - foot) / 2 print('Number of chickens:',int(y)) print('Number of rabbits:',int(head - y))