小编use*_*223的帖子

当我运行程序时,"无"一直出现

每当我运行我创建的计算器程序时,它工作正常,但文本"无"一直出现,我不知道为什么.这是代码:

def add():
    print 'choose 2 numbers to add'
    a=input('add this')
    b=input('to this')
    print a+b
    return menu()
def sub():
    print 'choose 2 numbers to subract'
    a=input('subract this')
    b=input('from this')
    print b-a
    return menu()
def menu():
    print "hello, Welcome"
    print "these are your options"
    print "1. add"
    print "2. sub"
print menu()
loop=2
def sys():
    while loop==2:
        a=input("please choose")
        if a==1:
            print add()
        elif a==2:
            print sub()
        else:
            return menu(),sys()
print sys()
Run Code Online (Sandbox Code Playgroud)

这是输出:

hello, Welcome
these are your options
1. add …
Run Code Online (Sandbox Code Playgroud)

python

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

序列中的随机字符串

有没有办法随机化一组字符串,就像你可以为整数?

我举个例子:

import random
random.randint(1, 30) #will produce random number between 1 and 30
Run Code Online (Sandbox Code Playgroud)

对于一个字符串,我想从一个set变量中随机化单词:

a="off","it","on","not"
random.randstr(a) #I understand that this isnt a real code and will produce and error
Run Code Online (Sandbox Code Playgroud)

有没有一种简单的方法可以实现这一目标?

python random

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

标签 统计

python ×2

random ×1