猜数字,设定一个理想数字比如:66,让用户输入数字,如果比66大,则显示猜测的结果大了,然后继续让用户输入; 如果比66小,则显示猜测的结果小了,然后继续让用户输入;只有等于66,显示猜测结果正确,然后退出循环。
while 1:
age=66
My_input = int(input('>>>'))
if My_input>age:
print('大了')
elif My_input<age:
print('小了')
else:
print('对了')
break
3次机会
在上一题的基础,设置:给用户三次猜测机会,如果三次之内猜测对了,则显示猜测正确,退出循环,如果三次之内没有猜测正确,则自动退出循环,并显示‘大笨蛋’
cont=1
while cont<4:
age=66
My_input = int(input('>>>'))
if My_input>age:
print('大了')
elif My_input<age:
print('小了')
else:
print('对了')
break
cont+=1
else:
print('大笨蛋')
判断下列逻辑语句的True,False
1 > 1 or 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6
not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6
8 or 3 and 4 or 2 and 0 or 9 and 7
0 or 2 and 3 and 4 or 6 and 0 or 3
6 or 2 > 1
6#2真前
3 or 2 > 1
0 or 5 < 4
5 < 4 or 3
2 > 1 or 6
3 and 2 > 1
0 and 3 > 1
2 > 1 and 3
3 > 1 and 0
3 > 1 and 2 or 2 < 3 and 3 and 4 or 3 > 2
使用while循环输出 1 2 3 4 5 6 8 9 10
conu=1
while conu<11:
if co
nu==7:
conu=conu+1
continue
print(conu)
conu+=1
求1-100的所有数的和
s=0
cont=1
while cont<101:
s+=cont
cont+=1
print(s)
输出 1-100 内的所有奇数 (奇数就是除以2余数1 %2==1)
conu=1
while conu<101:
if conu%2==1:
print(conu)
conu+=1
输出 1-100 内的所有偶数 (偶数就是除以2余数不为1)
conu=1
while conu<101:
if conu%2==0:
print(conu)
conu+=1
求1-2+3-4+5 ... 99的所有数的和
s=0#奇数
z=0
count=1
while count<100:
if count%2==1:
s=s+count
else:
z+=count
count+=1
print(s-z)#50
简述ASCII、Unicode、utf-8编码英文和中文都是用几个字节?
简述位和字节的关系?
8位一字节 8bit = 1Byte bit是字位,也就是计算机存储数据的“0”、“1”,每个“0”、“1”都是一个字位。Byte是字节,是文件存储的最小单位,一个字节由八个字位组成,前七位是文件的名称,最后一位是校验位。1Byte=8bit,1KB=1024Byte,1MB=1024KB,1GB=1024MB,1TB=1024GB。
"老男孩"使用GBK占几个字节,使用Unicode占用几个字节?
6,12
猜年龄游戏升级版 要求:允许用户最多尝试3次,每尝试3次后,如果还没猜对,就age=66,如果回答Y,就继续让其猜3次,以此往复,如果回答N,就退出程序,如何猜对了,就直接退出。
count=1 age=66 while count<4: My_input = int(input('>>>')) if My_input>age: print('大了你还有%s次机会'%(3-count)) elif My_input<age: print('小了你还有%s次机会'%(3-count)) else: print('对了哟大帅哥') break count+=1 if count==4: zz=input('y续命 n退出') if zz.upper()=='Y': count=1 if zz.upper()=='N': break
⽤用户输⼊入⼀一个数. 判断这个数是否是⼀一个质数(升级题).
# 质数,又称素数,是只能被1或者自己整除的自然数。 # 比1大但不是素数的数我们称之为合数,1和0即非素数也非合数 # 最小的素数是2,而最大的素数并不存在,这一点欧几里德已在其《几何原本》中证明
num = int(input("请输入一个数字!"))
i = 2
if num >= 2:
while i < num:
if num % i == 0:
print("您输入的数字%s不是质数!" % (num))
break
else:
i += 1
else:
print("您输入的数字%s是质数!"%(num))
else:
print("输入错误!")
a=input('>>>')
if a==1 or a==0:
print('不是')
elif a.isdecimal() and int(a)!=1 and int(a)!=0:
print('是')
else:
print('不是')
a=input('>>>')
if '最' or '第一' in a:
print('bux')
eles:
print('s')
输⼊⼀个数. 判断这个数是⼏位数(⽤算法实现)(升级题)
a=input('>>>')
print(len(a))