当前位置:网站首页>Truth value and conditional expression

Truth value and conditional expression

2022-07-18 14:56:00 qq_ forty-two million three hundred and seven thousand five hun

if 100print(" Truth value ")

Conditional expressions selectively assign values to variables

#!/usr/bin/python
# -*- coding: UTF-8 -*-
sex = None
if input(" Please enter gender :") == " male ":
    sex = 1
else:
    sex = 0
print(sex)

sex = 1 if input(" Please enter gender :") == " male " else 0
print(sex)

""" 1. Get an integer if it is an even number as a variable state Assign even number, otherwise odd number  2.  Enter the year. If it is a leap year, give the variable day assignment 28 otherwise 29 """

state = " Odd number " if int(input(" Please enter an integer :")) % 2 else " even numbers "
print(state)
year=int(input(" Please enter the year "))

day = 29 if year % 4 == 0 and year % 100 != 0 or year % 400 == 0 else 28
print(day)
原网站

版权声明
本文为[qq_ forty-two million three hundred and seven thousand five hun]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/199/202207160612583988.html