【问题标题】:converting from strings and integers... not sure what I am doing从字符串和整数转换......不知道我在做什么
【发布时间】:2018-02-20 19:00:32
【问题描述】:
int_one =input("Please enter a three-digit number thats first number is greater than last  ")
int_one_swap = (int_one[-1]+int_one[1:-1]+int_one[0])
print (int_one_swap)

print (int(int_one) - int(int_one_swap))
math_one = (int(int_one)-int(int_one_swap))
print (math_one)
int_two_swap = (int(math_one[-1]+int(math_one[1:-1])+ int(math_one[0]))
print (int_two_swap)
final = (int_two_swap + math_one)
print (final)
if final == 1089:
    print ("Your result is 1089")
else:
    print ("Your result is not 1089 so your first and last digits must have differed by less than 2")

遇到语法问题。 需要让程序运行所有这些命令并努力让它工作。教授说了一些关于整数和字符串的转换,但我就是不明白。请帮忙

【问题讨论】:

  • 1.请格式化代码和 2) 你使用什么编程语言?

标签: python string numbers integer mixing


【解决方案1】:
int_one =input("Please enter a three-digit number thats first number is greater than last ") 
int_one_swap = (int_one[-1]+int_one[1:-1]+int_one[0]) 
print (int_one_swap)
print (int(int_one) - int(int_one_swap)) 
math_one = (int(int_one)-int(int_one_swap)) 
print (math_one) 
int_two_swap = int(int(str(math_one)[-1])+int(str(math_one)[1:-1])+ int(str(math_one)[0])) 
print (int_two_swap) 
final = (int_two_swap + math_one) 
print (final) 
if final == 1089: 
  print ("Your result is 1089") 
else: 
  print ("Your result is not 1089 so your first and last digits must have differed by less than 2")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-09
    • 1970-01-01
    • 2021-04-13
    相关资源
    最近更新 更多