Lesson2 - homework
Posted lauce
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Lesson2 - homework相关的知识,希望对你有一定的参考价值。
Yep, my first home work, i am happy that i worked #13 out independently:)
7.利用if语句写出猜大小的游戏:
设定一个理想数字比如:66,让用户输入数字,如果比66大,则显示猜测的结果大了;如果比66小,则显示猜测的结果小了;只有等于66,显示猜测结果正确。
a = 66
for i in range(1,4):
b = float(input(‘pls guess the number:‘))
if b>a:
print(‘too big‘)
elif b<a:
print(‘too small‘)
else:
print(‘you got it‘)
break
"""9.提示用户输入麻花藤. 判断用户输入的对不对. 如果对, 提示真聪明, 如果不对, 提示你 是二货么"""
a = input("pls input ‘hello‘:")
if a == ‘hello‘:
print("good job, clever boy!")
else:
print("what‘s wrong with you?")
"""12.求1-2+3-4+5 ... 99的所有数的和"""
a = 0
b = 0
for i in range(1,100):
if i%2==0:
a-=i
else:
b+=i
print(a+b)
"""13.用户登陆(三次输错机会)且每次输错误时显示剩余错误次数
(提示:使用字符串格式化)"""
user = "admin"
password = "123"
for i in range(1,4):
a = input("pls input user name:")
b = input("pls input password:")
if a ==user and b == password:
print("you really a lucky boy!")
break
else:
m = 3 - i
if m != 0:
print("wrong user name or password, you can try %d more times"%m)
else:
print("wrong again, no chance anymore, pls contact administrator")
以上是关于Lesson2 - homework的主要内容,如果未能解决你的问题,请参考以下文章