mardi 10 décembre 2019

Getting wrong result when adding random values in string format

I'm trying to make a script that receives a number of desired random numbers as input, and then generates and prints them.

However, my script adds the numbers instead of joining the strings. I would like for the strings to join so it would generate the pins like:

Enter the amount of lunch pins to generate: 10

26141
128111
937502
2436
56516
83623
246317

My code:

import random

PTG = int(input("Enter the amount of pins to generate: \n"))
PG = 0
PS = ""

while PTG > PG:
 RN1 = random.randint(0, 9)
 RN2 = random.randint(0, 9)
 RN3 = random.randint(0, 9)
 RN4 = random.randint(0, 9)
 RN5 = random.randint(0, 10)
 RN6 = random.randint(0, 10)
 if RN1 == 0:
   PS += "0"
 elif RN1 == 1:
   PS += "1"
 elif RN1 == 2:
   PS += "2"
 elif RN1 == 3:
   PS += "3"
 elif RN1 == 4:
   PS += "4"
 elif RN1 == 5:
   PS += "5"
 elif RN1 == 6:
   PS += "6"
 elif RN1 == 7:
   PS += "7"
 elif RN1 == 8:
   PS += "8"
 elif RN1 == 9:
   PS += "9"
 elif RN2 == 0:
   PS += "0"
 elif RN2 == 1:
   PS += "1"
 elif RN2 == 2:
   PS += "2"
 elif RN2 == 3:
   PS += "3"
 elif RN2 == 4:
   PS += "4"
 elif RN2 == 5:
   PS += "5"
 elif RN2 == 6:
   PS += "6"
 elif RN2 == 7:
   PS += "7"
 elif RN2 == 8:
   PS += "8"
 elif RN2 == 9:
   PS += "9"
 if RN3 == 0:
   PS += "0"
 elif RN3 == 1:
   PS += "1"
 elif RN3 == 2:
   PS += "2"
 elif RN3 == 3:
   PS += "3"
 elif RN3 == 4:
   PS += "4"
 elif RN3 == 5:
   PS += "5"
 elif RN3 == 6:
   PS += "6"
 elif RN3 == 7:
   PS += "7"
 elif RN3 == 8:
   PS += "8"
 elif RN3 == 9:
   PS += "9"
 elif RN4 == 0:
   PS += "0"
 elif RN4 == 1:
   PS += "1"
 elif RN4 == 2:
   PS += "2"
 elif RN4 == 3:
   PS += "3"
 elif RN4 == 4:
   PS += "4"
 elif RN4 == 5:
   PS += "5"
 elif RN4 == 6:
   PS += "6"
 elif RN4 == 7:
   PS += "7"
 elif RN4 == 8:
   PS += "8"
 elif RN4 == 9:
   PS += "9"
 elif RN5 == 0:
   PS += "0"
 elif RN5 == 1:
   PS += "1"
 elif RN5 == 2:
   PS += "2"
 elif RN5 == 3:
   PS += "3"
 elif RN5 == 4:
   PS += "4"
 elif RN5 == 5:
   PS += "5"
 elif RN5 == 6:
   PS += "6"
 elif RN5 == 7:
   PS += "7"
 elif RN5 == 8:
   PS += "8"
 elif RN5 == 9:
   PS += "9"
 elif RN5 == 10:
   PS += ""
 elif RN6 == 0:
   PS += "0"
 elif RN6 == 1:
   PS += "1"
 elif RN6 == 2:
   PS += "2"
 elif RN6 == 3:
   PS += "3"
 elif RN6 == 4:
   PS += "4"
 elif RN6 == 5:
   PS += "5"
 elif RN6 == 6:
   PS += "6"
 elif RN6 == 7:
   PS += "7"
 elif RN6 == 8:
   PS += "8"
 elif RN6 == 9:
   PS += "9"
 print(PS)
 PG += 1
 PS = ""

Python version: 3.7.4




Aucun commentaire:

Enregistrer un commentaire