第三天,写代码好难呀~
怒买3斤核桃
#倒叙输出
str = input(‘请输入一串字符,字符之间逗号隔开:’)
print(str[::-1])
str = input(“请输入字符串”)
list = []
for x in range(len(str) -1,-1,-1): #range(start,stop,step)
list.append(str[x])
print(‘’.join(list)) #连接符
name = ‘mily’
age = 18
print(‘hello %s, 今年%s岁’%(name, age)) #分隔符
print(“8的八进制为等于:{😮}”.format(8)) # b o X
name = “mily”
age = 10
print(f’name is {name}, age is {age}')
#猜数字,共有10次机会
import random
x = random.randint(0,100)
for i in range(10):
guass = int(input(‘请输入您要猜测的数字:’)) #若想将元素加进循环就要将元素写进循环
if guass<x:
print(f’猜小了,请继续,还剩余%s次机会’%(9-i))
elif guass>x:
print(f'猜大了,请继续,还剩余%s次机会'%(9-i))
else:
print('猜对了')
break
if i == 9:
print(‘游戏结束,没有猜到’)
#判断是不是闰年,并输出当前日期是当年的第几天
year = int(input(‘请输入年份:’))
month = int(input(‘请输入月份’))
day = int(input(‘请输入日期’))
arr1 = [31,28,31,30,31,30,31,31,30,31,30,31]
arr2 = [31,29,31,30,31,30,31,31,30,31,30,31]
if year % 4 == 0 and year % 100 !=0 or year % 400 == 0:
print(‘今年为闰年’)
for i in range(month-1):
day+=arr2[month-1]
print(f’今天是{year}的第{day}天’)
else:
print(‘今年不是闰年’)
for i in range(month-1):
day+=arr1[month-1]
print(f'今天是{year}的第{day}天')
#猴子吃桃
p=1
for i in range(9,0,-1):
p = (p+1)*2+1
print(f’第{i}天,还剩多少{p}桃子’)
print(f’一共摘了{p}桃子’)