[問題] 新手請益一題簡單的if statement
大家好
新手想請教一題簡單的題目
但不知為何我的答案總是Z
似乎沒有成功loop
還請大家賜教 感謝!
題目:
Write a program that takes a character as input (a string of length 1), which
you should assume is an upper-case character; the output should be the next
character in the alphabet. If the input is 'Z', your output should be 'A'.
(You will need to use an if statement. )
我的code:
for i in range(65,90):
input=chr(i)
if input!="Z":
output=chr(ord(input)+1)
else:
output=="A"
print (output)
註:因為65-90就是A到Z的index
但我的code是不論他給我input為多少
我的program output都是Z
已經試了一兩小時都還沒找到原因
所以想請大家幫忙題點我一下
感恩
感謝~
--
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 68.180.87.229 (美國)
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1559497608.A.1D9.html
推
06/03 01:57,
5年前
, 1F
06/03 01:57, 1F
→
06/03 01:57,
5年前
, 2F
06/03 01:57, 2F
推
06/03 01:58,
5年前
, 3F
06/03 01:58, 3F
推
06/03 08:46,
5年前
, 4F
06/03 08:46, 4F
→
06/03 08:47,
5年前
, 5F
06/03 08:47, 5F
→
06/03 08:48,
5年前
, 6F
06/03 08:48, 6F
→
06/03 09:26,
5年前
, 7F
06/03 09:26, 7F
→
06/03 09:27,
5年前
, 8F
06/03 09:27, 8F
推
06/03 09:38,
5年前
, 9F
06/03 09:38, 9F
推
06/03 13:19,
5年前
, 10F
06/03 13:19, 10F
→
06/03 13:19,
5年前
, 11F
06/03 13:19, 11F
→
06/03 13:25,
5年前
, 12F
06/03 13:25, 12F
→
06/03 13:26,
5年前
, 13F
06/03 13:26, 13F
→
06/08 07:22,
5年前
, 14F
06/08 07:22, 14F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):