if statement practice

if statement practice

1. Write a sentence that judges whether a number can be divisible by 3 and 7 at the same time, and print out the result

num = int(input('请输入数字'))
if num % 3 ==0 and num % 7 ==0:
	print(num)
else:
	print('傻子,不可以')

2. Write a conditional statement that judges whether a number can be divisible by 3 or 7, but cannot be divisible by 3 or 7 at the same time, and print out the corresponding result

num = int(input('请输入数字'))
if (num % 3==0 or num % 7==0) and (num % 21 != 0):
    print(num)
else:
    print('这个数字不能哦!')

3. Enter the year, write the code to determine whether the entered year is a leap year, and print the corresponding result.

year = int(input('请输入年份'))
if (year % 4 ==0 and year % 100 != 0 ) or year % 400 ==0:
    print(year,'是一个闰年')
else:
    print(year,'不是一个闰年')

4. Assuming that today’s class time is 3718 seconds, how many hours, how many minutes, and how many seconds is today’s class calculated by programming, expressed in the form of XX hours, XX minutes, and XX seconds

x = 3718
hour = x//3600
minute = x // 3600
second = x % 60
print(hour,'时',minute,'分',second,'秒',sep='')

5. Define two variables to save a person's height and weight, and program to determine whether the person's body is normal!

Formula: The square value of weight (kg)/height (m) is normal between 18.5 and 24.9

weight = float(input('请输入体重(kg)'))
height = float(input('请输入身高(m)'))
BMI = weight/height**2
if 18.5<= BMI <=24.9:
    print('恭喜你,你是正常人!')
else:
    print('呜呜呜,要保持健康生活!')

Guess you like

Origin blog.csdn.net/deyaokong/article/details/109200514