a=float(input("输入一个数:"))
b=float(input("再输入一个数:"))
c=a+b
print(f"{a}+{b}的值是{c}")
import datetime
now=datetime.datetime.now()
print("你好,现在是",now.strftime("%H:%M:%S"))
#string format time %H %M %S是格式化符号,类似还有%Y %m %d
import random
print("我这里有一个1到100之间的数字,请你来猜猜看!")
number=random.randint(1,100)
while True:
a=int(input("你猜的数字是:"))
if a<number:
print("太小啦!")
elif a>number:
print("太大啦!")
else:
print(f"恭喜你!猜对了!这个数是{number}")
break
name=input("hello,我是python,你叫什么名字:")
print(f"你好呀,{name}")
mood=input("你今天心情怎么样呀?(输入happy/sad/others)")
if mood=="happy":
print("真好!祝你一天开心!")
elif mood=="sad":
print("没关系,一切都会变好的")
else:
print("希望你保持好心情~")
import random
a=random.randint(1,10)
print(f"你的幸运数字是:{a}")
print("输入两个整数a,b 其中a小于等于b")
a=int(input()) #以enter作为分隔
b=int(input())
c=random.randint(a,b)
print(f"你的幸运数字是:{c}")
import random
def gen_music():
songs=[
"特别的人",
"爱我还是他",
"稻香",
"Hotel California",
]
song=random.choice(songs)
print(f"听听 {song} 吧")
def gen_game():
games=[
"第五人格",
"原神",
"和平精英",
"蛋仔派对"
]
game=random.choice(games)
print(f"试试 {game} 吧")
print("觉得有些无聊?听音乐还是玩游戏?")
while True:
choice=int(input("输入1选择音乐,2选择游戏:"))
if choice==1 :
gen_music()
elif choice==2 :
gen_game()
else:
print("输入错误,重来一次吧")