-3

Question 1: I assume this will be converting to a shell script but my only issue do I need to change anything in my code? This is just simply to run a python script file.

cd ..
cd Bin\Randomizer
cls
python Randomizer.py

Question 2: When I have python scripts do I need python installed on that computer for the python script to work like I know on my end when I code I need it but what if I emailed it and someone started it do they need python? and if so is there a way to avoid this? so like when you head to a website and play a game it does not make you install python.

This is a script for example

import time
import random 
"""Randomizer Script"""
print("Randomizer Loaded!")
print()
time.sleep(3)
done = 0
while done == 0: 
    name = input("What is your name? ")
    print("Welcome " + name + " To Randomizer!")
    time.sleep(1)
    print("This program will randomize things for a chosen choice!")
    print()
    print("Before we start this program can only allow 6 names at a time")
    time.sleep(3)
    num = input("How Many Things Are You Randomizing? 2 - 6 ")
    def randomizer2():
        name1 = input("What Is the First Persons Name ")
        name2 = input("What Is the Second Persons Name ")
        chosennum = random.randint(1, 2)
        if chosennum == 1: 
            if name1.isalpha():
                chosenname = name1
                print("The Name "+chosenname+" Has Been Chosen!")
            else:
                print("Do Not Input Numbers Input Letters!")
        elif chosennum == 2: 
            if name2.isalpha():
                chosenname = name2
                print("The Name "+chosenname+" Has Been Chosen!")
            else:
                print("Do Not Input Numbers Input Letters!")
    def randomizer3():
        name1 = input("What Is the First Persons Name ")
        name2 = input("What Is the Second Persons Name ")
        name3 = input("What Is the Third Persons Name ")
        chosennum = random.randint(1, 3)
        if chosennum == 1: 
            if name1.isalpha():
                chosenname = name1
                print("The Name "+chosenname+" Has Been Chosen!")
            else:
                print("Do Not Input Numbers Input Letters!")
        elif chosennum == 2: 
            if name2.isalpha():
                chosenname = name2
                print("The Name "+chosenname+" Has Been Chosen!")
            else:
                print("Do Not Input Numbers Input Letters!")
        elif chosennum == 3:
            if name3.isalpha():
                chosenname = name3
                print("The Name "+chosenname+" Has Been Chosen!")
            else:
                print("Do Not Input Numbers Input Letters!")        
    def randomizer4():
        name1 = input("What Is the First Persons Name ")
        name2 = input("What Is the Second Persons Name ")
        name3 = input("What Is the Third Persons Name ")
        name4 = input("What Is the Fourth Persons Name ")
        chosennum = random.randint(1, 4)
        if chosennum == 1: 
            if name1.isalpha():
                chosenname = name1
                print("The Name "+chosenname+" Has Been Chosen!")
            else:
                print("Do Not Input Numbers Input Letters!")
        elif num == 2: 
            if name2.isalpha():
                chosenname = name2
                print("The Name "+chosenname+" Has Been Chosen!")
            else:
                print("Do Not Input Numbers Input Letters!")
        elif num == 3:
            if name3.isalpha():
                chosenname = name3
                print("The Name "+chosenname+" Has Been Chosen!")
            else:
                print("Do Not Input Numbers Input Letters!")

        elif chosennum == 4:
            if name4.isalpha():
                chosenname = name4
                print("The Name "+chosenname+" Has Been Chosen!")
            else:
                print("Do Not Input Numbers Input Letters!")
    def randomizer5():
        name1 = input("What Is the First Persons Name ")
        name2 = input("What Is the Second Persons Name ")
        name3 = input("What Is the Third Persons Name ")
        name4 = input("What Is the Fourth Persons Name ")
        name5 = input("What Is the Fifth Persons Name ")
        chosennum = random.randint(1, 5)
        if chosennum == 1: 
            if name1.isalpha():
                chosenname = name1
                print("The Name "+chosenname+" Has Been Chosen!")
            else:
                print("Do Not Input Numbers Input Letters!")
        elif chosennum == 2: 
            if name2.isalpha():
                chosenname = name2
                print("The Name "+chosenname+" Has Been Chosen!")
            else:
                print("Do Not Input Numbers Input Letters!")
        elif chosennum == 3:
            if name3.isalpha():
                chosenname = name3
                print("The Name "+chosenname+" Has Been Chosen!")
            else:
                print("Do Not Input Numbers Input Letters!")

        elif chosennum == 4:
            if name4.isalpha():
                chosenname = name4
                print("The Name "+chosenname+" Has Been Chosen!")
            else:
                print("Do Not Input Numbers Input Letters!")
        elif chosennum == 5: 
            if name5.isalpha():
                chosenname = name5
                print("The Name "+chosenname+" Has Been Chosen!")
            else:
                print("Do Not Input Numbers Input Letters!")
    def randomizer6():
        name1 = input("What Is the First Persons Name ")
        name2 = input("What Is the Second Persons Name ")
        name3 = input("What Is the Third Persons Name ")
        name4 = input("What Is the Fourth Persons Name ")
        name5 = input("What Is the Fifth Persons Name ")
        name6 = input("What Is the Sixth Persons Name ")
        chosennum = random.randint(1, 6)
        if chosennum == 1: 
            if name1.isalpha():
                chosenname = name1
                print("The Name "+chosenname+" Has Been Chosen!")
            else:
                print("Do Not Input Numbers Input Letters!")
        elif num == 2: 
            if name2.isalpha():
                chosenname = name2
                print("The Name "+chosenname+" Has Been Chosen!")
            else:
                print("Do Not Input Numbers Input Letters!")
        elif num == 3:
            if name3.isalpha():
                chosenname = name3
                print("The Name "+chosenname+" Has Been Chosen!")
            else:
                print("Do Not Input Numbers Input Letters!")

        elif chosennum == 4:
            if name4.isalpha():
                chosenname = name4
                print("The Name "+chosenname+" Has Been Chosen!")
            else:
                print("Do Not Input Numbers Input Letters!")
        elif num == 5: 
            if name5.isalpha():
                chosenname = name5
                print("The Name "+chosenname+" Has Been Chosen!")
            else:
                print("Do Not Input Numbers Input Letters!")

        elif num == 6:
            if name6.isalpha():
                chosenname = name6
                print("The Name "+chosenname+" Has Been Chosen!")
            else:
                print("Do Not Input Numbers Input Letters!")

    if num.isdigit() and num == "2": 
        randomizer2()
    elif num.isdigit() and num == "3":
        randomizer3()
    elif num.isdigit() and num == "4":
        randomizer4()
    elif num.isdigit() and num == "5":
        randomizer5()
    elif num.isdigit() and num == "6":
        randomizer6()
    else:
        print("Please Insert Numbers!")
    stay = input("Do You Want To Randomize Again? Y/N ")
    if stay == "Y":
        done = 0
    elif stay == "N":
        done = 1
        website = "Nothing :("
        print("Thank You For Using Are Programs for more visit " + website)
        time.sleep(7)
cccmdm
  • 9
  • 1
  • 2
  • Possible duplicate of [How to make a Python script standalone executable to run without ANY dependency?](http://stackoverflow.com/questions/5458048/how-to-make-a-python-script-standalone-executable-to-run-without-any-dependency) – lhk Jan 18 '17 at 09:41

1 Answers1

2

I frankly don't understand your first question. The code you are showing is definitely not converting anything. And python is not a shell script. What do you want to do ? If you want to execute a python script, you use python script.py in the terminal.

Regarding the second question:

If you mail someone your python code, they need to have a python interpreter installed to run it. The interpreter needs to be the correct python version, you can't run 2.x with 3.x and vice versa. They also need to have the libraries you are using.

That being said, there are ways to package python code. Look here: How to make a Python script standalone executable to run without ANY dependency?

If you want to execute a python script by clicking on it, these 3 steps should do the trick:

  1. Add this line to the top of your script: #!/usr/bin/env python . It should be the very first line of code.
  2. Mark the file as executable, run the following command in the terminal chmod +x script.py
  3. Edit your file explorer preferences. There should a setting which switches between "running" and "opening" executable script files.

After that just doubleclick on the script.

EDIT:

The first line of your code should be

#!/usr/bin/env python

or

#!/usr/bin/env python3

depending on the python version of your code.

Community
  • 1
  • 1
lhk
  • 27,458
  • 30
  • 122
  • 201
  • Actually there's a line that executes the python script, but it's not correctly formatted as code. I have edited the question to fix it, once is peer reviewed will be visible to everyone. –  Jan 18 '17 at 10:11
  • I've taken a look at the edit. That will indeed run the python file. What do you mean by "I assume this will be converting to a shell script". – lhk Jan 18 '17 at 10:15
  • 1
    I think he has a python code but wants to be able to execute it by double clicking a file (instead of going to console and typing `python Randomizer.py`) so he creates a bat file. The part he misses is that it will still require python interpreter, so best solution is what you answered. Make a standalone executable. –  Jan 18 '17 at 10:17
  • @SembeiNorimaki, I see. That makes sense – lhk Jan 18 '17 at 10:27
  • @SembeiNorimaki, your description of what the OP is thinking is probably right, but creating a batch file to allow executing a Python script in Windows Explorer is a poor solution. The default file association enables executing scripts by double clicking on them. If that was changed for some reason, it would be better to use a shortcut to execute the script. – Eryk Sun Jan 18 '17 at 14:04