python if条件语句练习

python if条件语句练习

-- coding:utf-8 --

@Time :2019/1/9 13:33

@Author :CoCoa

@Email :[email protected]

@File :MyEX3.py

@Software :PyCharm Community Edition

1.根据你输入的数据,来进行判断学生的成绩。输入数据函数:input()

score = int(input(“请输入分数: “))
print(””)
if score >=0 and score <60:
print(“不及格”)
elif score == 60:
print(“及格”)
elif score >60 and score <90:
print(“良好”)
elif score >=90 and score <=100:
print(“优秀”)
elif score >100:
print(“请输入0-100的整数”)
#退出提示
#input(“点击 enter 键退出”)

2、一家商场在降价促销,

如果购买金额50-100元(包含50元和100元)之间,会给10%的折扣,

如果购买金额大于100元会给20%折扣。

编写一程序,询问购买价格,再显示出折扣(%10或20%)和最终价格

bill=int(input(“请输入购买金额:”))

if bill<50:

print(“购买金额大于50才支持打折哦!”)

elif bill>=50 and bill<=100:

discount = 0.1

payment=bill*(1 - discount)

print(“打折后价格为:%f” %payment)

elif bill>100:

discount = 0.2

payment=bill* (1 - discount)

print(“打折后价格为:%f” %payment)

3、输入一个数,判断一个数n能同时被3和5整除

n = int(input(“判断一个数n能否同时被3和5整除,请输入一个整数:”))

if n%30 and n%50:

print ("%d能同时被3和5整除" %n)

else:

print("%d不能同时被3和5整除" %n)

4、输入一个年份,输出是否为闰年

闰年条件:能被4整除但不能被100整除,或者能被400整除的年份都是闰年

# N = int(input("请输入一个年份:"))
# if N % 400 == 0:
#     print("%d是闰年!" % N)
# elif N % 4 == 0 and N % 100 != 0:
#     print("%d是闰年!" % N)
# else:
#     print("%d不是闰年!" % N)

5、一个 5 位数,判断它是不是回文数。

即 12321 是回文数,个位与万位相同,十位与千位相同。

根据判断打印出相关信息。

a=input(‘请输入一个5位数:’)

if a[0]==a[4] and a[1]==a[3] :

print("%s是个回文数" %a)

else:

print("%s不是个回文数" %a)

6、生成随机整数,从1-9取出来。

然后输入一个数字,来猜,

如果大于,则打印bigger。

小了,则打印less。

如果相等,则打印equal。

#1.生成一个随机数

import random

a=random.randint(1,9)

#print (“随机数是 %d” %a)

#从控制台获取一个数

b=int(input(“please input a number:”))

#3.判断随机数与输入数据的大小

if b>a:

print("random is %d "%a, “,your number is bigger than the random!”)

elif b<a:

print(“random is %d “%a,”,your number is less than the random!”)

elif b==a:

print (“random is %d “%a,”,your number is equal than the random!”)

7.写一个餐厅菜单显示程序:(大概的设计模式如下)

请自己设计一个数据存储这些菜单,然后根据你从客户端输入的数据去进行菜名的读取。

比如说当我输入:平价菜中的苦瓜炒肉,就会显示有这道菜以及价格,否则就显示不存在这道菜。

menus = [“1,手撕包菜”, “2,大白菜”,“3,土豆丝”,“4,炒莴笋”,“5,上海青”,“6,青椒炒茄子”]

menu=int(input(“输入菜名:”))

if menu ==1:

print(“您点的菜是:手撕包菜” “,价格是:10元”)

elif menu == 2:

print(“您点的菜是:大白菜” “,价格是:10元”)

elif menu == 3:

print(“您点的菜是:土豆丝” “,价格是:10元”)

elif menu == 4:

print(“您点的菜是:炒莴笋” “,价格是:10元”)

elif menu == 5:

print(“您点的菜是:上海青” “,价格是:10元”)

elif menu == 6:

print(“您点的菜是:青椒炒茄子” “,价格是:10元”)

else:

print(“我们店没有这道菜”)


欢迎加我的微信交流学习:Cc2015123

猜你喜欢

转载自blog.csdn.net/weixin_42485712/article/details/86560158