python简单练习

1.py  hello python

 print("Hello python")

print("hello world")

2.py  变量计算

 num1=100
num2=200
result=num1+num2
print(result)

3.py  名片制作

#输入名字
name = "fanfen"
#输入年龄
age = 28
#输入电话号码
mobile_num = 18875992320
#输入公司地址
add = "北京昌平"
#输出名片
print("==================\n姓名:%s\n年龄:%d\n手机号码:%d\n公司地址:%s\n=================="%(name,age,mobile_num,add))

4.py  if 语句判断是否成年

ge = int(input("请输入年龄:"))
if age>=18:
    print("已成年")
else:
    print("未成年")
print("程序结束")


5.py  if 嵌套上公交

#coding = utf-8


balance = int(input("Please input the Bus card balance:"))
emptySeat = int(input("Please input the empty seat number:"))


if balance>=2:
    print("You can get on the bus.")
    if emptySeat!=0:
        print("You can have a seat.")
    else: print("You can't have a seat.")
else:
    print("You can't get on the bus.")


6.py  elif语句猜拳游戏

import random
player = int(input('请输入:石头(0),剪刀(1),布(2):'))
computer = random.randint(0,2)


if (player == 0 and computer ==1)or(player == 1 and computer == 2) or (player == 2 and computer == 0):
    print("You win!")
elif (player == computer):
    print("呵呵,暂时平局")
else:
    print("You lose!")


7.py while累加1-100

#/usr/bin/python3
#coding=utf-8


i=0
sum = 0
while i<=100:
    if i%2 == 0:
        sum+=i
        print("i=%d sum=%d"%(i,sum))
    i+=1
print("程序结束")


8.py  while 打印*号

#coding = utf-8


n=1
while n<=5:
    i=1
    while i<=n:
        print("*",end="")
        i+=1
    print()

    n+=1

9.py while嵌套九九乘法表

#coding=utf-8
j=1
while j<=9:
    i=1
    while i<=j:
        print("%d*%d=%d "%(j,i,i*j),end="")
        i+=1
    print()
    j+=1


for i in range(1, 10):
    for j in range(1, i+1):
        print("%d * %d = %d " % (j, i, i*j), end="\t")

    print()


10.py while 倒三角形

#coding=utf-8


j=5
while j>=1:
    i=1
    while i<=j:
        print("*",end="")
        i+=1
    print()

    j-=1


11.py while 两三角形对接

#coding = utf-8
#N=int(input("Please input a number that above 7:"))


N=9
j=1
while abs(N-j)/2<=(N-1)/2:
    i=1
    while i<=abs(N-j)/2:
        print(" ",end="")
        i+=1
    i=1
    while i<=(N-abs(N-j)):
        print("*",end="")
        i+=1
    j+=2
    print()


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值