我正在编写一个程序,对输入的int进行各种处理,但是如果其中一位数字为9,希望它执行不同的操作。我已经四处搜寻,但找不到适合的方法,到目前为止,这是我的代码:
Num = int(input("Enter a large number: "))
if Num # does not contain 9
Num2 = Num + 10
print("If I added 10 to your number it would be:", Num2)
print("The new number times 2 would be", Num2 * 2)
count = 0
number = Num
if (number.valueof(x).contains("9")):
print("No 9s plz")
else:
while (number > 9):
number = number // 10
count = count + 1
for i in range(1, count + 1):
Num = Num + 1 * (10**i)
i = i+1
print("adding one to every digit on your first number would be:", Num + 1)
else:
print("Sorry we dont do 9s")
答案 0 :(得分:0)
希望这会有所帮助。
Num = int(input("Enter a large number: "))
if Num!=9: #does not contain 9
Num2 = Num+10
print("If I added 10 to your number it would be:" , Num2)
print("The new number times 2 would be " , Num2*2)
count = 0; number = Num;
set1=set(str(number))
if "9" in set1:
print("No 9s plz")
else:
while (number > 9):
number = number//10
count = count + 1
for i in range(1,count+1):
Num = Num+1*(10**i)
i = i+1
print("adding one to every digit on your first number would be: " , Num + 1)
else:
print("Sorry we dont do 9s")