作者yeuan (心要够坚定)
看板Python
标题Re: [问题] 新手请益一题简单的if statement
时间Tue Jun 4 09:40:14 2019
原po的回圈跑完只有存到ord(89) 也就是Y 所以答案永远是Z
提供我的写法 顺便确保不能输入A-Z以外的东西
check_lst = [chr(i) for i in range(65,91)]
char = input('Enter an upper-case character: ')
if char in check_lst:
if char == 'Z':
print('A')
else:
print(chr(ord(char)+1))
else:
print('You need to enter an upper-case character.')
※ 引述《AmigoSafin ()》之铭言:
: 大家好
: 新手想请教一题简单的题目
: 但不知为何我的答案总是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), 来自: 67.249.65.90 (美国)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1559612416.A.6B3.html
※ 编辑: yeuan (67.249.65.90 美国), 06/04/2019 09:41:37
1F:→ bibo9901: ..... 06/06 05:09
2F:推 AmigoSafin: 谢谢大家的帮忙~ 06/08 07:21