Python列表中的字符串输入

时间:2016-10-16 06:30:12

标签: python python-2.7 python-3.x

我想制作一个非常简单的脚本,它将执行以下操作:

1-我有一个名单名为tries = [“First”,“Second”,“Last”]

2-我希望用户为每次尝试创建一个输入字符串

所以我制作了如下脚本:

print("You got 3 Guessing tries to guess What is My Name")

tries = ["First", "Second", "Last"]

for x in tries:
    Names = str(input(x,"Guess ?"))

    print(Names)

但似乎Python不接受这一行:Names = str(输入(x,“猜猜?”))

所以有任何建议如何让问题向用户显示为:“First Guess?”,然后是“Second Guess?”,然后是“last guess?”

2 个答案:

答案 0 :(得分:0)

print("You got 3 Guessing tries to guess What is My Name") tries = ["First", "Second", "Last"] for x in tries: Names = str(input("{} Guess ?".format(x))) print(Names) 函数仅包含一个参数。在这里,你给它两个。

我猜你想做的是

format

如果您想了解更多关于<?xml version="1.0" encoding="UTF-8"?> <!-- This is a sample dictionary source file. It can be built using Dictionary Development Kit. --> <d:dictionary xmlns="http://www.w3.org/1999/xhtml" xmlns:d="http://www.apple.com/DTDs/DictionaryService-1.0.rng"> <d:entry id="dictionary_application" d:title="Dictionary application"> <d:index d:value="Dictionary application"/> <h1>Dictionary application </h1> <p> An application to look up dictionary on Mac OS X.<br/> </p> </d:entry></d:dictionary> on devdocs

的信息

马特

答案 1 :(得分:0)

不需要

首先关闭str()因为输入总是输出一个字符串

其次这是python 3.x而不是2.7(在标记中)

第三你遇到的问题是你正在尝试提供输入2参数,这适用于打印并抛出新的python编码器,但其他功能不会允许它。您可以通过简单地将两个字符串添加到一起来修复它,如<Application x:Class="WpfApplication1.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:WpfApplication1" StartupUri="MainWindow.xaml"> <Application.Resources> <Style x:Key="algo" TargetType="{x:Type Button}"> <Setter Property="Background" Value="Red" /> </Style> </Application.Resources>