学习Python的第二天
Posted theneverlemon
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了学习Python的第二天相关的知识,希望对你有一定的参考价值。
1、今天学习了循环语句
2、以下是一些小程序
import math
a,b,c=map(float,input(‘Enter a,b,c:‘).split(‘,‘))
root_=(b*b)-(4*a*c)
if root_>0:
root_1=(-b+math.sqrt(b*b-4*a*c))/2*a
root_2=(-b-math.sqrt(b*b-4*a*c))/2*a
print(‘The roots are %f and %f‘%(root_1,root_2))
elif root_==0:
root_1=(-b+math.sqrt(b*b-4*a*c))/2*a
print(‘The root is %f‘%root_1)
else:
print(‘The equation has no real roots‘)
import random
num1=random.randint(0,100)
num2=random.randint(0,100)
print(num1,num2)
sum=num1+num2
sum_=int(input(‘请输入两个数的和:‘))
if sum_==sum:
print(‘正确‘)
else:
print(‘错误‘)
today=int(input(‘Enter today:‘))
day_num=int(input(‘Enter the number of days elapsed since today:‘))
week=[‘Sunday‘,‘Monday‘,‘Tuesday‘,‘Wednesday‘,‘Thursday‘,‘Friday‘,‘Saturday‘]
futureweek=today+day_num
now=0
now=futureweek%7
print("Today is %s and the future day is %s"%(week[today],week[now]))
num1,num2,num3=map(int,input(‘请输入三个整数:‘).split(‘,‘))
x=[num1,num2,num3]
x.sort()
print(x)
weight_1,price_1=map(float,input(‘Enter weight and price for package1:‘).split(‘,‘))
weight_2,price_2=map(float,input(‘Enter weight and price for package2:‘).split(‘,‘))
vaule_1=weight_1/price_1
vaule_2=weight_2/price_2
if vaule_1>vaule_2:
print(‘Package1 has the better price‘)
elif vaule_1==vaule_2:
print(‘same‘)
else:
print(‘Package2 has the better price‘)
year,month=map(int,input(‘输入年份和月份:‘).split(‘,‘))
if (year % 4==0 and year %100 !=0 )or (year%400==0):
day_=int(‘29‘)
else:
day_=int(‘28‘)
if month==1 or month==3 or month==5 or month==7 or month==8 or month==10 or month==12:
day=int(‘31‘)
elif month==4 or month==6 or month==9 or month==11:
day=int(‘30‘)
else :
day=day_
print(‘%d 年%d月份有%d天‘%(year,month,day))
import numpy as np
computer=np.random.choice([‘正面‘,‘反面‘])
hum=input(‘请输入你的选择:‘)
print(computer)
if computer == hum:
print(‘正确‘)
else:
print(‘错误‘)
import random
s=int(input(‘剪刀(0), 石头(1), 布(2): ‘))
i=random.randint(0,2)
print(i)
if (s == 0 and i == 2) or (s == 1 and i == 0) or (s == 2 and i == 1):
print(‘You won.‘)
elif s==i:
print(‘ping‘)
else:
print(‘Loser‘)
y=int(input(‘Enter year:(e.g.,2008):‘))
m=int(input(‘Enter month:1-12:‘))
d=int(input(‘Enter the day of the month:1-31:‘))
a=[‘Saturday‘,‘Sunday‘,‘Monday‘,‘Tuesday‘,‘Wednesday‘,‘Thurday‘,‘Firday‘]
if m==1:
m=13
y=y-1
if m==2:
m=14
y=y-1
h=int(d + ((26 * (m + 1) ) // 10) + (y % 100) + ((y % 100) / 4) + ((y // 100) / 4) + 5 * y // 100) % 7
o=a[h]
print(‘Day of the week is %s‘%o)
import numpy as np
daxiao=np.random.choice([‘Ace‘,‘2‘,‘3‘,‘4‘,‘5‘,‘6‘,‘7‘,‘8‘,‘9‘,‘10‘,‘Jack‘,‘Queen‘,‘King‘])
huase=np.random.choice([‘梅花‘,‘红桃‘,‘方块‘,‘黑桃‘])
print(‘你选择的牌是‘,huase,daxiao)
num=int(input(‘输入一个三位整数:‘))
bai=num//100
shi=num//10%10
ge=num%10
if bai==ge:
print(‘是回文数!‘)
else:
print(‘不是回文数‘)
a,b,c=map(float,input(‘Enter three edges:‘).split(‘,‘))
if (a+b)>c and (a+c)>b and (b+c)>a:
print(‘The perimeter is %.0f‘%(a+b+c))
else:
print(‘不合法‘)
以上是关于学习Python的第二天的主要内容,如果未能解决你的问题,请参考以下文章