为什么我的数据打印在括号中

时间:2017-03-20 21:45:17

标签: python file reader

这是我的代码

package multiplicationquiz;

import static java.lang.System.out;
import java.util.Random;
import java.util.Scanner;

public class MultiplicationQuiz {

    final static Scanner cin = new Scanner(System.in);
    final static Random rand = new Random();

public static void main(String[] args) {
    out.println("Welcome to the Multiplication Table Quiz\n");
    out.print("Enter your given name (no spaces): ");
    String name = cin.next();
    out.println("\nGreetings, " + name + ". I will ask you 10 problems.");
    out.println("Ready, set, go!");

    int qno;
    int numCorrect = 0, numProbs = 10;
    for (qno = 1; qno <= 10; qno++){
        if (oneProblem(qno) == true){
            out.println("Your answer is correct!");
            numCorrect ++;
        }
        else
            out.println("Your answer is wrong. The correct answer is ");               
    } // end for
    report(name, numProbs, numCorrect);
} // end main

static boolean oneProblem(int qno) {
    int number1 = 1 + rand.nextInt(10), number2 = 1 + rand.nextInt(10);        

    out.print("\nProblem " + qno + ": What is " + number1 + " times " 
              + number2 + "? ");        
    int answer = cin.nextInt();

    if (answer == number1 * number2)
        return true;
    else 
        return false;
} // end oneProblem

static void report(String name, int numProbs, int numCorrect) {
    out.print("Test report for " + name + "\n\n");
    out.print("Problems attempted: " + numProbs + "\n");
    out.print("Correct answers: " + numCorrect + "\n");
    out.print("Incorrect answers: "  + (numProbs - numCorrect) + "\n");

    if (numCorrect == 10)
        out.print("Congratulations! You got a perfect score.");
    if (numCorrect < 10 && numCorrect >= 8)
        out.print("You did all right.");
    if (numCorrect < 8 && numCorrect >= 7)
        out.print("You pass, but you should try to do better.");
    if (numCorrect < 7)
        out.print("You really need to study harder.");

} // end report
static int getInt(String prompt) {
    out.print(prompt);
    return cin.nextInt();
    }  
}

我的实际输出是: [&#39; zyzzyvas&#39;]

从中读取的文件包含以下条目: zythem zyzzyvas

我只是想让它打印字符串而不是其他东西我错过了什么?

谢谢你们!

2 个答案:

答案 0 :(得分:0)

尝试使用print ( (' ').join(row))

答案 1 :(得分:0)

您可以将join行重新打包成以下字符串:

with open(sys.argv[1], 'rt') as f:
    reader = csv.reader(f)
    for row in reader:
       print ' '.join(row)