【发布时间】:2018-04-26 13:34:39
【问题描述】:
在以下代码中需要一些帮助,因为它进入无限循环并且不验证用户输入:get_offset 是函数。刚刚编辑需要一些帮助,以在定义的函数中完成加密部分
def get_offset(offset):
while True:
value = (offset)
if value < 1:
print("")
if value > 94:
print("")
return offset
my_details = display_details()
get_choice = get_menu_choice()
print(my_details)
print(get_choice)
count = 10
while count > 0:
count -=1
encrypted = ""
choice = int(input("What would you like to do [1,2,3,4,5]: "))
while choice <1 and choice > 5:
print("Invalid choice, please enter either 1, 2, 3, 4 or 5.")
if choice == 1:
string_input = input("Please enter string to encrypt: ")
input_offset = get_offset(int(input("Please enter offset value (1 to 94): ")))
**for letter in string_input:
x = ord(letter)
encrypted += chr(x + input_offset)
if x < 32:
x += 94
if x > 126:
x -= 94
print(encrypted)**
【问题讨论】:
-
在你的第一个 while 循环中,你永远不会改变“偏移量”,所以它每次都在做同样的事情 ==> 无限循环
-
那么阿里需要编辑什么?我是初学者
-
@JaySadat 为了便于阅读,我编辑了您的帖子。您的代码需要缩进以支持降价,以便读者能够区分您的要求和您的代码是什么。
-
JaySadat:连续两次重复同一个问题是完全不可接受的:你之前在 Apr 23 上问过,说 *“请帮帮我。我需要一个快速回复。我真的很感激吗?”,我回答。你所做的只是抱怨答案。然后你昨天又问了。这种行为会让你在 SO 上被禁止。
标签: python validation input