Towards the first day of programming

Save my programming notes.

1.Given a time value (in milliseconds), convert it into days, hours, minutes, seconds, and milliseconds, as shown:

Input

Output

186,400,500 milliseconds

2 days, 3 hours, 46 minutes, 40 seconds, and

500 milliseconds

// 1.input函数接收用户输入的内容(输入内容为str类型,因为str类型可以把用户输入的内容全部包括),返回str类型(input后会返回一个str类型的值,该值可以不接收,可以拿一个str类型去接收)

//2.int函数强制把str类型转换为整型

//3.写法为int(string类型)

Code:

MSECS = int(input("Please enter the number of milliseconds:")); 

msec = MSECS%1000
temp = MSECS/1000

second = temp%60
temp = temp/60

minute = temp%60
temp = temp/60

hour = temp%24
day = temp/24

print("days:",int (day),"hours:",int (hour),"minutes:",int (minute),"seconds",int (second),"msecs:",msec); 

2.

圆形或方形

  • 提示用户“如果要计算圆的面积,请输入 c,其他为正方形”,并根据用户的输入,执行以下操作:

如果输入是“c”(字符 c),请根据以下公式计算圆的面积:
A = π r2

其中 r 是圆的半径(用户输入),π = 3.14159

  • 如果输入不是“c”,则根据用户输入的边长计算正方形的面积

Code:

x = input("Enter a character :");
r = int(input("Enter a number :"));
b = int(input("Enter a number :"));
 
if(x == 'c'):
    pi=3.14159;
    A = pi*r**2;
    print("The area of the circle:",A);
    
else:
        B = b*b;
        print("The area of the square:",B);

3.

提示用户输入“what”,输入 4 次和输出用户实际输入“什么”的次数。 如果没有任何输入是“what”,则显示“You have not said what once”

Code:

a=input("Enter:");
b=input("Enter:");
c=input("Enter:");
d=input("Enter:");
i=0;

if(a=="what"):
    i=i+1;

if(b=="what"):
    i=i+1;
    
if(c=="what"):
    i=i+1;
    
if(d=="what"):
    i=i+1;

print("The number of times you enter what is",i)

if(a!="what" and b!="what" and c!="what" and d!="what"):
    
    print("You have not said what once.")

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值