小编Ros*_*hty的帖子

Ruby中的选项菜单

我试图在Ruby中创建一个菜单,以便根据用户输入的内容,取决于调用哪个类.然后在这种情况下,它将返回"Main"或类"Options".

我希望有一个人可以帮助我.这是我的代码.

module Physics
G = 21
C = 20000
Pi = 3.14
D = 100
end

class Options
puts "Please select 1 for Acceleration and 2 for Energy."
option = gets()
if option == 1
then
puts "AccelCalc" # This is the bit that needs to direct the user to the class AccelCalc
else
puts "EnergyCalc" # This needs to take them to EnergyCalc.
end
end

class AccelCalc
include Physics
puts "Please enter the mass of the object"
M …
Run Code Online (Sandbox Code Playgroud)

ruby

5
推荐指数
2
解决办法
5853
查看次数

传递由用户设置的变量作为os.system()命令的参数

好吧基本上我是Python的新手,但是,我想为我在工作中使用的所有基本工具制作一个简单的菜单系统我的代码到目前为止如下:

import os
def main():
    print "Main Menu.\n"
    print "1. Ping yourself.\n"
    print "2. Ping someone else.\n"
    opt = raw_input ("Please enter a number:- ")
    if opt == "1":
            os.system('ping 127.0.0.1')
    if opt == "2":
            ip = raw_input ("Please enter IP:- ")
            os.system('ping'.ip)

main()
Run Code Online (Sandbox Code Playgroud)

现在,一切都运行良好,但我似乎在这里停留在这一行:

os.system('ping'.ip)
Run Code Online (Sandbox Code Playgroud)

因为我想使用第10行的变量来在命令中使用.希望这是一个简单的解决方案.

谢谢,

罗斯.

python

1
推荐指数
1
解决办法
1万
查看次数

标签 统计

python ×1

ruby ×1