【发布时间】:2019-09-08 16:38:21
【问题描述】:
所以我正在尝试学习 python,并且我已经编写了这段代码,它应该从随机单词和随机数列表中生成句子,我已经开始使用这段代码,但我不确定它是否会工作
这是我的代码:
import random
num = random.randrange(0, 9)
drug = ['Advil', 'Synthroid', 'Crestor', 'Nexium', 'Vyvanse', 'Lyrica']
form = ['capsule', 'tablet', 'Powder', 'gel', 'liquid solution', 'Eye drops']
lines = []
for item in drug, form:
line = '- the patient was prescribed [' + num + '](dosage) [' + item.form + '](form) of [' + item.drug + '] for [' + num + 'days](Duration)
lines.append(line)
这是我期待的结果:
[the patient was prescribed [1](Dosage) [capsule](Form) of [Advil](Drug) for [5 days](Duration),
the patient was prescribed [2](Dosage) [Powder](Form) of [Nexium](Drug) for [6 days](Duration),
the patient was prescribed [5](Dosage) [luiquid solution](Form) of [Vyvanse](Drug) for [4 days](Duration),
...]
【问题讨论】:
-
你的代码里的药物是什么?
-
我的意思是 ''for item in drug, form:''
标签: python python-3.x random