python怎么重新输入_如何从用户输入重置/重新启动Python中的程序?

我想重置/重新启动我的程序,但基于用户输入。因此,假设用户键入“yes”并单击enter,程序将重置/重新启动并重新启动。我正在做一个能量计算器;物理问题。输出是机械能、动能和势能。所有的公式都正确编码,一切都按预期工作,除了我没有办法重新启动程序,不点击回文件并重新打开。#Importing "time" and "math" so I can use the time.sleep and rounding functions

import time

import math

restart=1

user_r1=float(input ("What is the mass of your object (kg) = "))

print ("")

user_r2=float(input ("Whats is the height you are dropping from (m) = "))

print ("")

user_r3=float(input ("What is the velocity (m/s) = "))

#Formulas that solve from the inputs given

EKinetic = 0.5 * user_r1 * user_r3 * user_r3

EPotential = user_r1 * 9.81 * user_r2

MechEnergy = (EPotential) + (EKinetic)

#Rounding - To change the ammount of sigdigs change the # infront of the f'

EKinetic='%.1f' % EKinetic

EPotential='%.1f' % EPotential

MechEnergy='%.1f' % MechEnergy

#Spitting out the info the user will see

print ("")

print ("===============================================================================")

print ("Kinetic Energy = ",EKinetic,"J")

print ("")

print ("Potential Energy = ",EPotential,"J")

print ("")

print ("Mechanical Energy = ",MechEnergy,"J")

print ("===============================================================================")

print ("")

#This time.sleep will make the program pause for (x# of seconds)

time.sleep(3)

user_r4=(input ("To do another calculation type yes and hit enter = "))

if user_r4 == ("yes"):

print ("YAY")

###PUT RESTART CODE HERE###

###EVERYTHING DOWN ARE JUST PLACE HOLDERS FOR THE RESTART CODE###

else:

print ("Please type yes to continue")

time.sleep(1)

user_r4=(input ("To do another calculation type yes and hit enter = "))

if user_r4 == ("yes"):

print ("YAY")

###PUT RESTART CODE HERE###

else: print ("Thats enough!!!")

time.sleep(3)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值