Sep-09-2019, 08:28 PM
Hey guys. I have a task that's about working with Random Generated Numbers.
So basically I need to:
Create a program that allows the user to play the lottery.
● Generate a random two-digit number (between 10 and 99) this number will be the lottery number.
● Ask the user to enter any two-digit number this will be the user's guess.
● Get the first and second digit from the two-digit lottery number.
● Get the first and second digit from the user's guess.
● Print out the generated lottery number.
● If the user's guess matches the lottery number exactly, print out "Congratulations you have an exact match, you win R10 000.00" (i.e. if the user enters 12 and the lottery number is 12)
● If the user's guess matches the lottery numbers, but are in the wrong order print out "Congratulations you have all digits, you win R5 000.00" (i.e. if the user enters 48 and the lottery number is 84)
● If the user guesses one digit correctly print out "Congratulations you have one correct digit, you win R1 000.00". (i.e. if the user enters 27 and the lottery number is 78)
● Else print out "Sorry no match"
I wrote the code as I think it should go its still work in progress, but my main problem is I cannot seem to separate the random two-digit number from each other and save them as separate variables. I also cant manage to reverse the random-two digit number using an extended slice.
LINE 5
LINE 6
LINE 7
:is where I am struggling to get them separated etc.
I have no problem to separate the users two digit number but I cannot do the same with the randomly generated two-digit number.
Here is my work in progress:
Kind Regards
YoungGrassHopper
So basically I need to:
Create a program that allows the user to play the lottery.
● Generate a random two-digit number (between 10 and 99) this number will be the lottery number.
● Ask the user to enter any two-digit number this will be the user's guess.
● Get the first and second digit from the two-digit lottery number.
● Get the first and second digit from the user's guess.
● Print out the generated lottery number.
● If the user's guess matches the lottery number exactly, print out "Congratulations you have an exact match, you win R10 000.00" (i.e. if the user enters 12 and the lottery number is 12)
● If the user's guess matches the lottery numbers, but are in the wrong order print out "Congratulations you have all digits, you win R5 000.00" (i.e. if the user enters 48 and the lottery number is 84)
● If the user guesses one digit correctly print out "Congratulations you have one correct digit, you win R1 000.00". (i.e. if the user enters 27 and the lottery number is 78)
● Else print out "Sorry no match"
I wrote the code as I think it should go its still work in progress, but my main problem is I cannot seem to separate the random two-digit number from each other and save them as separate variables. I also cant manage to reverse the random-two digit number using an extended slice.
LINE 5
LINE 6
LINE 7
:is where I am struggling to get them separated etc.
I have no problem to separate the users two digit number but I cannot do the same with the randomly generated two-digit number.
Here is my work in progress:
import random RandomNr = random.randint(10,99) UserNum = input("Enter any two-digit number: ") RandomNr1 = RandomNr[0] RandomNr2 = RandomNr[1] RandomNr3 = RandomNr[::-1] UserNum1 = UserNum[0] UserNum2 = UserNum[1] print(RandomNr) if UserNum == RandomNr: print("Congratulations you have an exact match, you win R10 000.00") elif UserNum == RandomNr3: print("Congratulations you have all digits, you win R5 000.00") elif (UserNum1 == RandomNr1)or(UserNum1 == RandomNr2): print("Congratulations you have one correct digit, you win R1 000.00") elif (UserNum2 == RandomNr1)or(UserNum2 == RandomNr2): print("Congratulations you have one correct digit, you win R1 000.00") else: print("Sorry no match")Thanks in advance for any assistance.
Kind Regards
YoungGrassHopper