python - 如何在 Python 3 中获取结果后重复此代码
问题描述
我编写了一个 python 代码来查找指数值。现在我想在得到一个数字的结果后自动重新运行这段代码,这意味着无限次询问另一个数字
# Function to Find Exponential Value of any Number
def expo(num, exp):
result = num ** exp
return result
# Taking Input
Number = int(input("Please Enter Desired Number: "))
Exponent = int(input("Please Provide Power Value: "))
# Passing to Function
ExpoVal = expo(Number, Exponent)
# String Section
str1 = "Exponential Value of %s" % Number
str2 = " with Power of %s" % Exponent
str3 = " is :"
str_concatenate = str1 + str2 + str3
# Output Result
print(str_concatenate, ExpoVal)
解决方案
您可以将整个代码添加为单个函数,然后通过while True:
循环运行它。这使它无限运行:
def Expo():
Number = int(input("Please Enter Desired Number: "))
Exponent = int(input("Please Provide Power Value: "))
result = Number ** Exponent
str1 = "Exponential Value of %s" % Number
str2 = " with Power of %s" % Exponent
str3 = " is :"
str_concatenate = str1 + str2 + str3
print(str_concatenate, ExpoVal)
while True:
Expo()
推荐阅读
- css - Vue:当输入框更改为禁用时如何更改其背景颜色
- mysql - Amazon Redshift 创建外部架构 MySQL 未启用
- php - 404 Not Found,路由和控制器有什么问题
- python - 使用 Panda 和 BeautifulSoup 附加结果
- python - 如何增加 Selenium 连接超时
- visual-studio - 如何在 vscode 中编辑时更改 div 的颜色、类名
- javascript - Web 开发 - 设置 firebase firestore 问题
- python - 显示来自 Opencv 代码的未知 C++ 异常的 Mediapipe 网络摄像头代码
- ruby-on-rails - 在Rails中使用Rspec检查属性值时未定义的方法
- sql - 您可以加入 2 个 PIVOT SQL 视图 - 有可能吗?