[英]How to ask for a boolean input from a user to qualify if statements and print a sentence using that information in Python
[英]How to print a user output by a sentence using python
我在python中有一个字典,如下所示:
dict1 = {'a':1, 'b':2, 'c':3}
到目前为止,我已经在Python 3中运行以下代码:
for key, value in dict1.items() :
print (key* value,end='')
这给了我输出: cccbba
我的问题是如何打印出来
Your answer : cccba.
像这样:
dict1 = {'a':1, 'b':2, 'c':3}
print ("Your answer : ",end='')
for key, value in dict1.items() :
print (key* value,end='')
您应该真正了解str.format
:
>>> print("Your answer: {0}".format("".join([k * v for k, v
in dict1.items()])))
Your answer: acccbb
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.