1、Python基礎&demo
模擬使用者登入
name = input('請輸入使用者名稱')
password = input('請輸入密碼')
if name == 'root':
if password == 'root':
print('登入成功')
else:
print('密碼錯誤')
else:
print('賬號錯誤')
num = input('請輸入一個a-c的字元')
if num == 'a':
print('A')
elif num == 'b':
print('B')
elif num =='c':
print('C')
else:
print('超出範圍了')
簡易版計算器
num1 = int(input('請輸入第一個數字'))
fu = input('請輸入符號')
num2 = int(input('請輸入第二個數字'))
if fu == '+':
num3 = num1 + num2
elif fu == '-':
num3 = num1 - num2
elif fu == '*':
num3 = num1 * num2
elif fu == '/':
num3 = num1 / num2
else:
print('符號不解析')
print(num3)
計算一個數是奇數還是偶數
num = int(input('請輸入一個數'))
if num % 2 == 0:
print('偶數')
else:
print('奇數')
用while迴圈輸入1-10,沒有7
count = 0
while count < 10:
count = count + 1
if count == 7:
continue
else:
print(count)
用while求1-100的和
my_sum = 0
count = 1
while count <= 100:
my_sum = my_sum + count
count = count + 1
print(my_sum)
一百以內的偶數,換成0的話就是奇數
count = 1
while count <= 100:
if count % 2 == 1:
pass
count = count + 1
else:
print(count)
count = count + 1
num = 1
while num <=3:
name = input('輸入名字')
if name == 'root':
print('登入成功')
break
else:
print('不正確')
num = num + 1