周末任务

花韻仙語
发布: 2024-12-02 09:03:01
转载
941人浏览过

周末任务

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
登录后复制

以上就是周末任务的详细内容,更多请关注php中文网其它相关文章!

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:dev.to网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号