问题是,打印“这是一个非常大的数字”,每多出一个数字,就会有一个“真的”(所以15表示“这是一个非常大的数字”,150表示“这是一个非常大的数字”,1500表示“这是一个非常大的数字”,依此类推。)
输入是一个整数,列出的唯一要求是代码应正确运行任何整数,应使用while循环将数字除以10,并应使用+=添加到字符串的末尾
x = input(("input an integer: "))
count = len(x)
y = int(x / 10)
countx = count - 1
print("that's a " + count("really") + " big number")我真的不知道我做了什么,但我可以说它是不正确的
发布于 2021-04-30 11:20:11
试试这个吧。使用while循环将数字除以10,并使用+=将数字与字符串相加。您将需要获取一个字符串变量,然后随着计数的增加追加到该变量。循环将运行到编号>= 10作为您提到的条件。
x = int(input(("input an integer: ")))
str=""
while x>=10:
x=x//10
str+="really "
print("that's a " + str + "big number")发布于 2021-04-30 13:12:33
添加了您在问题中所述的while循环
strVar = ""
y = 0
length = 0
cnt = 0
finished = False
num = input("Type a number: ")
while not finished:
y = int(num)//10
length = int(len(str(y)))
if length <= cnt:
finished = True
else:
strVar += " really"
cnt += 1
print("That's a" + strVar + " big number!")发布于 2021-04-30 11:04:39
尝尝这个
x = int(input("enter an integer"))
print("that's a " + 'really '*(len(str(x))-1) + " big number")如果您想要更正您的函数,请使用以下代码
x = input(("input an integer: "))
count = len(x)
y = int(x) / 10
countx = count - 1
print("that's a " + countx*" really" + " big number")https://stackoverflow.com/questions/67327636
复制相似问题