PHP前端开发

周末任务

百变鹏仔 5天前 #Python
文章标签 周末

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

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

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

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

3.英尺到米换算:

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

4.求正方形的面积:

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

5.求矩形的面积:

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

6.求圆的面积:

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

7.sgd 到 inr 换算:

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

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

from datetime import datetime, timedeltacurrent= 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-differenceprint("indian time:",difference.strftime("%h:%m:%s"))
singapore time: 01:32:00difference between singapore and indian time 2:30:00indian time: 23:02:00

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

no=7count=0while 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=36difference=2while 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=22difference=1while 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=53difference=13while 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=21even_no=9count=0while 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=3difference=1while 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=14count=0while 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