如何根据用户输入打印字符串 x 次 [英] How to print a string x times based on user input

查看:46
本文介绍了如何根据用户输入打印字符串 x 次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

免责声明:我是 Python 和编码的新手

我正在尝试制作一个简单的应用程序,它将打印一个单词特定的次数.

I am trying to make a simple application that will print a word a specific number of times.

现在运行我的代码,尽管我最初输入了 (times),但程序在退出前只会打印 (word) 一次.

Running my code now, despite my initial input for (times) the program will only print (word) once before exiting.

这是我的代码:

# Double Words

times = input('Ho w many times would you like to repeat your word?')

word = input('Enter your word:')

for times in times:
    print(word)

推荐答案

您可以使用:

for n in range(int(times)):

   print(word)

但这可能会给您带来错误,就像用户输入非整数值一样.

But this may give you error as if the user enters a non-integer value.

这篇关于如何根据用户输入打印字符串 x 次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆