预先警告,我刚开始学习Python,这是我第一次在这个网站上学习.如果我的行为像n00b,请不要讨厌.
所以我创建了一个程序,它应该告诉你以光速和光速的因素来到达星(指定距离)需要多长时间.它从一个名为easygui的库开始,它创建了一个很好的窗口,用户可以选择一个因子.他们选择的因素成为变量"选择".这部分代码工作正常.理想情况下,该值将被输入到一个函数中,该函数将进行分解,并返回行程天数的值.这是不成功的.最有可能的是,我只是设置错了,所以如果有人知道使用函数的正确方法,我真的很感谢你的帮助!哦,我试着疯狂地评论,所以希望一切都有意义!
import easygui as eg #the gui creation library I am using
dist = 41000000000000 #distance to the star
light = 300000 #speed of light
def Convert (factor): #takes in factor chosen by user
speed = light*factor #the speed is the factor multiplied by the speed of light
time = (dist/speed)/3600 # the time is the distance/divided by the speed, since thats a huge value in seconds, the /3600 should reduce it to days
return time #"should" return the …
Run Code Online (Sandbox Code Playgroud) 假设我的程序在启动时需要声明以下变量:
Pos_List = []
Room_List = []
Type_List = []
Spec_List = []
Sub_List = []
Rtr_List = []
IPa_List = []
MAC_List = []
Run Code Online (Sandbox Code Playgroud)
目前要做到这一点,我完全如上所示.我的问题是,有没有更短的方法来做到这一点,甚至一种方法在一条线上做到这一切?在我的程序中有几次出现这种情况,并占用了大量空间.有什么建议?谢谢.