Open roberthsu2003 opened 3 months ago
try:
number = int(input("請輸入整數:"))
if(number>0):
print(f"{number}是正整數")
if(number<0):
print(f"{number}是負整數")
if(number==0):
print(f"{number}是0")
if(number%2==1):
print(f"{number}是奇數")
if(number%2==0):
print(f"{number}是偶數")
except Exception as error:
print(error)
try:
number=int(input("請輸入一個整數"))
if number //2 ==0:
print(f"輸入{number}為偶數")
else:
print(f"輸入{number}為質數")
if number < 0:
print(f"輸入{number}為負數")
elif number > 0:
print(f"輸入{number}為正數")
else:
print(f"輸入為0")
except Exception as error:
print(error)```
try:
n = int(input("請輸入一個整數"))
except:
print("輸入格式錯誤")
else:
if(n > 0):
if(n % 2 == 0):
print(f"""{n}是正整數
{n}是偶數""")
else:
print(f"""{n}是正整數
{n}是奇數""")
elif(n < 0):
if(n % 2 == 0):
print(f"""{n}是負整數
{n}是偶數""")
else:
print(f"""{n}是負整數
{n}是奇數""")
else:
print(f"""{n}為零
{n}是偶數""")
try:
num = int(input("請輸入整數:"))
except:
print("輸入格式錯誤")
else:
if num>0:
print(f"{num}是正整數")
if num<0:
print(f"{num}是負整數")
if num==0:
print(f"{num}是0")
if num % 2==0:
print(f"{num}是偶數")
else:
print(f"{num}是奇數")
try:
number = int(input("請輸入整數:"))
if number < 0 :
print(f"{number}是負整數")
if number > 0 :
print(f"{number}是正整數")
if number == 0 :
print(f"{number}是0")
if number % 2 == 1 :
print(f"{number}是奇數")
if number % 2 == 0 :
print(f"{number}是偶數")
except:
print("輸入格式有誤")
try:
number = int(input("請輸入整數:"))
if number < 0:
print(f"{number}為負數")
if number == 0:
print(f"{number}為0")
if number > 0:
print(f"{number}為正數")
if number % 2 == 1:
print(f"{number}為奇數")
if number % 2 == 0:
print(f"{number}為偶數")
except Exception as error:
print(error)
try:
number = int(input("請輸入整數:"))
if number > 0:
print(f'{number}是正整數')
if number < 0:
print(f'{number}是負整數')
else :
print(f'{number}為0')
if number %2 == 0:
print(f'{number}為偶數')
else :
print(f'{number}為奇數')
except Exception as error:
print(error)
try:
num=int(input("請輸入整數"))
if num>0:
print(f"{num}是正數")
if num<0:
print(f"{num}是負數")
if num==0:
print(f"{num}是零")
if num%2==1:
print((f"{num}是奇數"))
if num%2==0:
print((f"{num}是偶數"))
except Exception as error:
print(error)
try:
number = int(input("請輸入一個整數"))
if(number > 0):
print(f"{number}為正整數")
if(number == 0):
print(f"{number}為零")
if(number < 0):
print(f"{number}為負整數")
if(number % 2 == 1):
print(f"{number}為奇數")
if(number % 2 == 0):
print(f"{number}為偶數")
except Exception as error: print(error) print("應用程式結束")
必需檢查輸入格式錯誤
輸入
輸出