2021年3月16日

时间:1.5个小时左右

代码:80行左右

博客:1

知识点:Python基础点

今天按着视频学习了Python基础

这个是代码:

import random

print("hollower")

# 数据类型
name = "如花"
print(type(name))
age = 18
print(type(age))
classes = "python"
height = 1.68
print("我是" + name + ",今年" + str(age) + ",我最擅长的科目是" + classes)
print("我是%s,今年%d,身高是%1.2f,我最擅长的科目是%s" % (name, age, height, classes))

# 流程控制语句:1.顺序结构 2.选择结构 3.循环结构

# 选择结构 if else ,模拟一个超市打折的活动,,,满500打八折,200-500打九折

money = float(input("请输入您购物的总金额:"))
if money >= 500:
    money = money * 0.8
    print("您打八折后的金额是:%.2f" % money)
elif 200 <= money < 500:
    print("您打九折后的金额是:%.2f" % money)
else:
    print("您应付的金额是:%2f" % money)

print("谢谢惠顾欢迎下次光临")

# 循环结构 while 0-10之间的整数

# 定义初始变量
a = 0
# 判断条件
while a < 10:
    print("Hello everyone!")
    a += 1

# 猜数字游戏:系统随机生成一个1-100的随机数
# 用户去猜。如果猜的小了提示小了继续,猜的大了提示大了继续,相等就是猜中了停止游戏

computer = random.randint(0, 100)  # 包含0-100
print("猜数字")

while True:
    player = int(input("请输入0-100之间的数:"))
    if player == computer:
        print("恭喜您猜对了!!")
        break
    elif player > computer:
        print("猜大了!")
        # continue # 用不用continue都可
    elif player < computer:
        print("猜小了")
原文地址:https://www.cnblogs.com/j-y-s/p/14903176.html