【问题标题】:getting a repatted generated answer in python在 python 中得到一个 repatted 生成的答案
【发布时间】:2017-09-10 16:37:18
【问题描述】:

我正在尝试制作一个程序,可以帮助我使用 Radius 查找区域。但是它的输出很奇怪,看看吧!

Pi = 3.1415929203539825
print('What is the Radius') #asking for Radius
R = input()
A = str(Pi) * int(R) * int(R)
print("The Area of this circle will be " + str(A) + "") 

当 R = 5 时,输出如下:

3.14159292035398253.14159292035398253.14159292035398253.14159292035398253.14159292035398253.14159292035398253.14159292035398253.14159292035398253.14159292035398253.14159292035398253.14159292035398253.14159292035398253.14159292035398253.14159292035398253.14159292035398253.14159292035398253.14159292035398253.14159292035398253.14159292035398253.14159292035398253.14159292035398253.14159292035398253.14159292035398253.14159292035398253.1415929203539825

【问题讨论】:

  • 你乘以一个字符串。将字符串相乘重复字符串.
  • 为什么将Pi 转换为字符串?
  • str(Pi) * int(R) * int(R) 更改为 Pi* int(R) * int(R)

标签: python-3.x math


【解决方案1】:

您不需要将 pi 转换为字符串。这样做会重复字符串

试试这个

from math import pi
R = float(input("enter a radius: "))
A = pi * (R**2)

【讨论】:

  • 非常感谢!你可能不知道,我只有 12 岁,我只有 2 小时的编码经验 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-14
  • 1970-01-01
相关资源
最近更新 更多