练习2


温度转化:
while True: a = int(input("摄氏度转华氏请按1\n华氏转摄氏请按2:\n")) if a == 1: celsius = float(input('输入摄氏温度:')) fahrenheit = (celsius * 1.8)/32 print('{:.2f}摄氏温度转为华氏温度为{:.2f}'.format(celsius,fahrenheit)) elif a == 2: fahrenheit = float(input("请输入华氏温度:")) celsius = 5/9*(fahrenheit-32) print('{:.2f}华氏温度转换为摄氏温度为:{:.2f}\n'.format(fahrenheit,celsius)) else: break

  

 

数字猜谜:

number = 12
guess = -1
print("数字猜谜游戏")
while guess != number:
     guess = int(input("请输入你猜的数字:"))
     if guess == number:
         print("恭喜,猜对了!")
     elif guess < number:
         print("猜的数字小了...")
     elif guess > number:
         print("猜的数字大了...")

  

 

学号,身份证数字:

stuNum='201606050015'
print('年级是:'+stuNum[0:4])
print('专业编号是:'+stuNum[4:9])
print('序号是:'+stuNum[-3:])

IDNo='441700199708060015'
print('省市'+IDNo[0:2])
print('生日'+IDNo[6:14])
print('性别'+IDNo[16])

  

 

字符串:

str = 'Hello welcome to'
print
str
print
str[0]
print
str[3:6]
print
str[3:]
print
str * 3
print (str + "http://news.gzcc.cn/")
print (str + " http://news.gzcc.cn/")

  

for i in range(1,20):
    print('http://news.gzcc.cn/html/xiaoyuanxinwen/'+str(i)+'.html')

  

 

posted @ 2018-09-10 10:05  陈松林  阅读(140)  评论(0)    收藏  举报