Python 3.3 Hello程序

Python 3.3 Hello程序,python,python-3.3,Python,Python 3.3,我被要求创建一个使用for循环和另一个程序for while循环的程序,我得到了这个for for循环,但我正在尝试设置我希望它重复myName的次数。如果可以,请帮助我,提前谢谢 # This program says hello and asks for my name. print('Hello world!') print('What is your name?') myName = input() for Name in myName (1,10): print('It

我被要求创建一个使用for循环和另一个程序for while循环的程序,我得到了这个for for循环,但我正在尝试设置我希望它重复
myName
的次数。如果可以,请帮助我,提前谢谢

# This program says hello and asks for my name.
print('Hello world!')

print('What is your name?')

myName = input()

for Name in myName (1,10):

    print('It is nice to meet you, ' + myName)
myName
是一个字符串,因此您无法调用它,括号就是这样做的。如果要将名称重复一定次数,应在以下范围内进行迭代:

这会将问候语打印10次

for i in range(10):
    print('It is nice to meet you, ' + myName)
注意:对于您的代码,您应该使用输入()而不是原始输入()。我只使用了raw_input(),因为我有一个过时的编译器/解释器

Python3.x(3.5)


问题是什么?@user2796887谢谢!最新答案
for i in range(10):
    print('It is nice to meet you, ' + myName)
# your code goes here
print('Hello world!')

print('What is your name?')

#I use raw_input() to read input instead
myName = raw_input()

#ask user how many times you would like to print the name
print('How many times would you like your name to repeat?')
#raw_input() reads as a string, so you must convert to int by using int()
counter = int(raw_input())

#your main issue is here
#you have to use the range() function to go a certain length for for-loops in Python
for x in range(counter):
    print('It is nice to meet you, ' + myName)
#Just the hello world
print('Hello world!')

#use input() to let the user assign a value to a variable named myName
myName = input('What is your name?:')

#now let the user assign an integer value to the variable counter for how many times their name should be repeated. Here i am enclosing the input of the user with an int() to tell python that the data type is an integer
counter = int(input('how many times do you want to repeat your name?:'))

#Use the Range function to repeat the names
for a in range(counter):
    print('It is nice to meet you, ' + myName)