当前位置:网站首页>Select statement if else

Select statement if else

2022-07-18 14:56:00 qq_ forty-two million three hundred and seven thousand five hun

Let the program execute the corresponding code according to the conditions

#!/usr/bin/python
# -*- coding: UTF-8 -*-
"""  Select statement  """

sex = input(" Please enter gender :")
if sex == " male ":
    print(" Hello! , sir !")
elif sex == " Woman ":
    print(" Hello! , ma'am !!!")

else:
    print(" Unknown sex ")


Debugging code
Interrupt the program , Execute sentence by sentence and observe the execution process
1. Add breakpoint at pycharm Click in the code, and a small red dot will appear on the left. This is where you want to interrupt
 Insert picture description here
2. Right click on the debug Enter mode mode , Press f8 Execute the program step by step

#!/usr/bin/python
# -*- coding: UTF-8 -*-
price = int(input(" Single price of goods :"))

num = int(input(" The number of :"))
count_price = int(input(" Amount obtained :"))
price_1 = count_price - price * num
if price_1 >=0:

    print(" Finally, it should be retrieved " + str(price_1))

    # print(" The money is not enough ")
else:
    print(" The money is not enough ")

    # price_1 = count_price - price * num
    # print(" Finally, it should be retrieved " + str(price_1))
"""  Get a quarter   Displays the corresponding month  """
quarter = input(" Please enter quarter :")

if quarter == " In the spring ":
    print("1,2,3")

elif quarter == " In the summer ":
    print("4,5,6")
elif quarter == " autumn ":
    print("7,8,9")
elif quarter == " In the winter ":
    print("10,11,12")


a1 = float(input(" Input number :"))
a2 = input(" Please enter operator :")
a3 = float(input(" Input number :"))

if a2 == "+":
    result = a1 + a3
    print(result)
elif a2 == "-":
    result = a1 - a3
    print(result)
elif a2 == "*":
    result = a1 * a3
    print(result)
elif a2 == "/":
    result = a1 / a3
    print(result)
else:
    print(" Operator error !!!")
num_1 = int(input(" Please enter a number :"))
num_2 = int(input(" Please enter a number :"))
num_3 = int(input(" Please enter a number :"))
num_4 = int(input(" Please enter a number :"))
#  Suppose the first largest posterior surface is compared , Find larger alternative hypotheses 
max_num = num_1

if max_num < num_2:
    max_num = num_2
if max_num < num_3:
    max_num = num_3
if max_num < num_4:
    max_num = num_4

print(max_num)
#!/usr/bin/python
# -*- coding: UTF-8 -*-
"""  Enter the score on the console to judge excellent / good / pass / fail, / Incorrect input  """
result = int(input(" Please enter the grade :"))
if result < 0 or result > 100:
    print(" Incorrect input ")
elif result >= 90:
    print(" good ")
elif result >= 80:
    print(" good ")
elif result >= 60:
    print(" pass ")

elif 0 <= result:
    print(" fail, ")

"""  Enter the month to get the number of days  """
month = int(input(" Please enter a month :"))
if month < 1 or month > 12:
    print(" Incorrect input ")
elif month == 2:
    print("28 God ")
elif month == 4 or month == 6 or month == 9 or month == 11:
    print(30)
else:
    print(31)
原网站

版权声明
本文为[qq_ forty-two million three hundred and seven thousand five hun]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/199/202207160612584069.html