登录后查看本帖详细内容!
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
number1=random.randint(0,9) number2=random.randint(0,9) number3=random.randint(0,9) guess1,guess2,guess3=eval(input('输入三个一位整数:')) number=number1+number2+number3 guess=guess1+guess2+guess3 print(number==guess ifnumber==guess else number==guess) 4.3: a,b,c,d,e,f=eval(input('输入a,b,c,d,e,f')) if a*d-b*c==0: print('The equation has no solution') else: x=(e*d-b*f)/(a*d-b*c) y=(a*f-e*c)/(a*d-b*c) print('x is'+str(x)+'and'+str(y)) 4.4: import random number1=random.randint(0,99) number2=random.randint(0,99) guess1,guess2=eval(input('输入两个小于100的整数:')) number=number1+number2 guess=guess1+guess2 print(number==guess ifnumber==guess else number==guess) 4.5: today_number=eval(input('今天是星期几:')) day_list=['星期天','星期一','星期二','星期三','星期四','星期五','星期六'] today=day_list[today_number] oneday_number=eval(input('输入今天之后到未来某天的天数:')) oneday_number=(today_number+oneday_number)% 7 oneday=day_list[oneday_number] print('today is '+str(today)+'and the futureday is '+str(oneday)) 4.6: weight,hight_feet,hight_inches=eval(input('输入体重,身高(英尺),身高(英寸)')) weight=0.45359237*weight hight_feet=12*0.0254*hight_feet hight_inches=0.0254*hight_inches bmi=weight/(hight_feet+hight_inches)**2 print('BMI is '+str(bmi)) if bmi<18.5: print('超轻') elif18.5<=bmi<25.0: print('标准') elif25.0<=bmi<30.0: print('超重') elif30.0<=bmi: print('痴肥') 4.7: amount=eval(input('输入美元,末尾两位代表美分:')) dollars=amount//100 remainingAmount=amount% 100 quarters=remainingAmount//25 remainingAmount=remainingAmount% 25 dimes=remainingAmount//10 remainingAmount=remainingAmount% 10 nickels=remainingAmount//5 remainingAmount=remainingAmount% 5 pennies=remainingAmount if dollars==1: 美元='dollar' else: 美元='dollars' if quarters==1: 两角五分='quarter' else: 两角五分='quarters' if dimes==1: 一角='dime' else: 一角='dimes' if nickels==1: 五分='nickel' else: 五分='nickels' if pennies==1: 美分='penny' else: 美分='pennies' print(str(dollars)+美元+str(quarters)+两角五分+str(dimes)+一角+str(nickels)+五分+str(pennies)+美分) 4.8: number1,number2,number3=eval(input('输入三个整数:')) if number1>number2: number1,number2=number1,number2 if number1>number3: number1,number3=number1,number3 else: number1,number3=number3,number1 else: number1,number2=number2,number1 if number1>number3: number1,number3=number1,number3 else: number1,number3=number3,number1 print(number3,number2,number1) 4.9: weight1,price1=eval(input('第1种包装重量和价钱')) weight2,price2=eval(input('第2种包装重量和价钱')) if price1 / weight1 > price2 / weight2: print('package 2 has the better price') elif price1 / weight1 < price2 / weight2: print('package 1 has the better price') else: print('error') 4.10: import random number1=random.randint(-(1E+2),1E+2) number2=random.randint(-(1E+2),1E+2) print(number1,number2,number1*number2) 4.11: year,month=eval(input('输入年和月:')) if (year % 4 == 0and year % 100 != 0) or year % 400 == 0: if month == 2: days = 29 elif month ==1or month == 3or month == 5or month == 7or month ==8or month ==10or month ==12: days=31 else: days=30 else: if month ==1or month == 3or month == 5or month == 7or month ==8or month ==10or month ==12: days=31 elif month == 2: days=28 else: days=30 print(days) 4.12: number=eval(input('输入一个整数:')) if (number % 5 == 0or number % 6 == 0) \ andnot (number % 5 == 0and number % 6 == 0): print(number,'is divisible by 5 or 6,but not both') elif number % 5 == 0and number % 6 == 0: print(number,'is divisible by 5 and 6') else: print(number,'is not dicisible by 5 or 6')
|