Hello! 欢迎来到小浪资源网!

周末任务


周末任务

1.华氏温度到摄氏度转换:

def fahrenheit_to_celsius():     celsius=(fahrenheit-32)*5/9     return celsius  fahrenheit=float(input("enter the fahrenheit:")) celsius=fahrenheit_to_celsius() print("celsius :",round(celsius,1)  
enter the fahrenheit:102.3 celsius : 39.1 

2.摄氏度到华氏度转换:

def celsius_to_fahrenheit():     fahrenheit=celsius*9/5+32     return fahrenheit  celsius=float(input("enter the celsius:")) fahrenheit=celsius_to_fahrenheit() print("fahrenheit :",round(fahrenheit,1))  
enter the celsius:39.1 fahrenheit : 102.4 

3.英尺到米换算:

def feet_to_meter():     meter=feet*0.3048     return meter  feet=float(input("enter the feet:")) meter=feet_to_meter() print("meter :",round(meter,3))  
enter the feet:12 meter : 3.658 

4.求正方形的面积:

def area_of_square():     area=side**2     return area  side=float(input("enter the side:")) area=area_of_square() print("area :",round(area,2))  
enter the side:12.3 area : 151.29 

5.求矩形的面积:

def area_of_rectangle():     area=length*width     return area  length=float(input("enter the length:")) width=float(input("enter the width:")) area=area_of_rectangle() print("area :",round(area,2))  
enter the length:13.4 enter the width:9.6 area : 128.64 

6.求圆的面积:

def area_of_circle():     area=3.14*radius**2     return area  radius=float(input("enter the radius:")) area=area_of_circle() print("area :",round(area,2)) 
enter the radius:7.2 area : 162.78  

7.sgd 到 inr 换算:

def sgd_to_inr():     inr=63.14*sgd     return inr  sgd=float(input("enter the sgd:")) inr=sgd_to_inr() print("inr:",round(inr,2))  
enter the sgd:23 inr: 1452.22 

8.新加坡时间与印度标准时间换算:

from datetime import datetime, timedelta  current= datetime.now() current_time= current.strftime("%h:%m:%s") print("singapore time:",current_time)  difference= timedelta(hours=2, minutes=30) print("difference between singapore and indian time",difference)  difference=current-difference print("indian time:",difference.strftime("%h:%m:%s")) 
singapore time: 01:32:00 difference between singapore and indian time 2:30:00 indian time: 23:02:00 

9) 7, 10, 8, 11, 9, 12, 10

no=7 count=0 while count<7:     print(no, end=" ")     if count%2==0:         no=no+3     else:         no=no-2     count+=1 
7, 10, 8, 11, 9, 12, 10 

10) 36, 34, 30, 28, 24, 22

no=36 difference=2 while no>=22:     print(no,end=" ")     if difference==2:         no=no-difference         difference+=2     else:         no=no-difference         difference-=2 
36, 34, 30, 28, 24, 22 

11) 22, 21, 23, 22, 24, 23

no=22 difference=1 while no<25:     print(no,end=" ")     if difference==1:         no=no-difference         difference+=1     else:         no=no+difference         difference-=1 
22, 21, 23, 22, 24, 23 

12) 53, 53, 40, 40, 27, 27

no=53 difference=13 while no>=27:     print(no, end=" ")     print(no, end=" ")     if difference==13:         no=no-difference  

53, 53, 40, 40, 27, 27

13) 21, 9, 21, 11, 21, 13, 21

odd_no=21 even_no=9 count=0 while count<7:      if count%2==0:         print(odd_no,end=" ")     else:         print(even_no,end=" ")         even_no=even_no+2     count+=1 
21, 9, 21, 11, 21, 13, 21  

14) 3, 4, 7, 8, 11, 12

no=3 difference=1 while no<=12:     print(no,end=" ")     if difference==1:         no=no+1         difference+=2     else:         no=no+3         difference-=2  
3, 4, 7, 8, 11, 12 

15) 14, 28, 20, 40, 32, 64

no=14 count=0  while count<6:      if count%2==0:         print(no, end=" ")         no=no*2     else:         print(no, end=" ")         no=no-8     count+=1 
14, 28, 20, 40, 32, 64 

相关阅读