简体   繁体   English

Python centOS无输出

[英]Python centOS no output

I recently started learning Python, like 5 days ago and my problem is, when I try to run script from the vps, nothing happens. 我最近开始学习Python,就像5天前一样,我的问题是,当我尝试从vps运行脚本时,什么也没发生。 The script is located in the /root directory and I tried to chmod it. 该脚本位于/ root目录中,我尝试对其进行chmod。 The file calls "alfa.py" and yes, i included a shebang line(or however you call that) 该文件名为“ alfa.py”,是的,我包含了一个shebang行(或者您称其为)

I tried to 我试过了

chmod +x alfa.py

Still no output! 仍然没有输出! This is the script (yeah.. very strange.. was just bored) 这是脚本(是的。。很奇怪。只是无聊)

#! /usr/bin/python

import time
import urllib2
import socket
import sys
import random
import os
from time import sleep
from random import randint

def cls():
    os.system("clear")

def choices():
    print "1.IDgen\n"
    print "2.socks\n"
    print "3.XatBot (Not working)\n"
    print "4.Calculator (not working)\n"
    print "5.XatRaid(not working) \n"
    print "6.Exit\n"
    choicechoice = int(raw_input("What do you want(The number)\n"))
        if choicechoice = 6:
            exit()
        elif choicechoice = 5:
            print "Not working yet...\n"
            cls()
            choices()
        elif choicechoice = 4:
            print "Not working yet..\n"
            cls()
            choices()
        elif choicechoice = 3:
            print "Will be done soon...\n"
            cls()
            choiches()
        elif choicechoice = 1:
            cls()
            idgen()
        elif choicechoice = 2:
            print "Almost done\n"
            cls()
            time.sleep(2)
            choices()

def main():
    print "Welcome to the main menu!\n"
    time.sleep(3)
    print "Before we start the program, we will ask you a couple of questions\n"
    time.sleep(3)
    cls()
    name = raw_input("What is your name?\n")
    time.sleep(2)
    age = int(raw_input("How old are you?\n")
    time.sleep(2)
    country = raw_input("In what country do you live?\n")
    time.sleep(2)
    print "Thanks for the info!\n"
    time.sleep(2)
    cls()
    valid = raw_input("Is this info valid? Answer with y or n\n")
        if valid == "y"
            print "Thanks for submitting your real info!\n"
            cls()
            print "Soo, your real name is {} and you live in {} and your real age is {} ? Nice!\n".format(name, country, age)
            choices()
        else:
            exit()

def idgen():
    id = urllib2.urlopen("http://xat.com/web_gear/chat/auser3.php").read()
    if "&UserId" in id:
        file = open("idss.txt","w")
        file.write(id+"\n")
        file.close()
        print "ID generated!\n"
        time.sleep(2)
    else:
        print "Not an id... um??\n"
        time.sleep(2)
    choices()

main()

When I do python alfa.py Nothing happens! 当我做python alfa.py什么都没发生!

You have multiple syntax errors in your code: 您的代码中存在多个语法错误:

Use == to test for equality. 使用==测试是否相等。

all if statement must end in : 所有if语句必须以:结尾

choiches() is not the same as choices() choiches()choices()

All opening ( must have a closing ) int(raw_input("How old are you?\\n") <- missing ) 所有开头(必须有一个结尾) int(raw_input("How old are you?\\n") <-缺少)

This is your code with correct syntax, go to the directory it is in and run it with python alfa.py : 这是使用正确语法的代码,转到其所在的目录并使用python alfa.py运行它:

import time
import urllib2
import socket
import sys
import random
import os
from time import sleep
from random import randint


def cls():
    os.system("clear")


def choices():
    print "1.IDgen\n"
    print "2.socks\n"
    print "3.XatBot (Not working)\n"
    print "4.Calculator (not working)\n"
    print "5.XatRaid(not working) \n"
    print "6.Exit\n"
    choicechoice = int(raw_input("What do you want(The number)\n"))
    if choicechoice == 6: # use `==` not =
        exit()
    elif choicechoice == 5:
        print "Not working yet...\n"
        cls()
        choices()
    elif choicechoice == 4:
        print "Not working yet..\n"
        cls()
        choices()
    elif choicechoice == 3: 
        print "Will be done soon...\n"
        cls()
        choices() # choices not  choiches()
    elif choicechoice == 1:
        cls()
        idgen()
    elif choicechoice == 2:
        print "Almost done\n"
        cls()
        time.sleep(2)
        choices()


def main():
    print "Welcome to the main menu!\n"
    time.sleep(3)
    print "Before we start the program, we will ask you a couple of questions\n"
    time.sleep(3)
    cls()
    name = raw_input("What is your name?\n")
    time.sleep(2)
    age = int(raw_input("How old are you?\n")) # missing a closing paren
    time.sleep(2)
    country = raw_input("In what country do you live?\n")
    time.sleep(2)
    print ("Thanks for the info!\n")
    time.sleep(2)
    cls()
    valid = raw_input("Is this info valid? Answer with y or n\n")
    if valid == "y":
        print "Thanks for submitting your real info!\n"
        cls()
        print "Soo, your real name is {} and you live in {} and your real age is {} ? Nice!\n".format(name, country, age)
        choices()
    else:
        exit()


def idgen():
    id = urllib2.urlopen("http://xat.com/web_gear/chat/auser3.php").read()
    if "&UserId" in id:
        file = open("idss.txt", "w")
        file.write(id + "\n")
        file.close()
        print "ID generated!\n"
        time.sleep(2)
    else:
        print "Not an id... um??\n"
        time.sleep(2)
    choices()


main()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM