Python Forum
Some line code explanation
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Some line code explanation
#4
numberInput[0] was probably supposed to be some kind of ID, maybe even a name. I think the purpose of the code is to enter some form of ID and 6 numbers.

I would put the "verify input" in a function. This code loops until the user enters valid input.
winning_numbers =  {10, 11, 8, 1, 5, 20}

def get_info():
    """Input name and 6 unique lottery number choices"""
    name = input("Enter you name: ")
    while True:
        numbers = input("Enter your 6 lottery numbers separated by spaces: ").split()
        if len(numbers) != 6:
            print("Should be 6 Numbers")
            continue

        if len(set(numbers)) != 6:
            print("There can be no duplicates")
            continue

        # Convert the numbers to integers
        try:
            numbers = list(map(int, numbers))
        except ValueError:
            print("Numbers must be integers")
            continue

        return name, numbers

name, entered_numbers = get_info()
prize = len(winning_numbers & set(entered_numbers)) * 100
if prize > 0:
    print(name, "won", prize ,"pesos!")
else:
    print(name, "won nothing!")
Reply


Messages In This Thread
Some line code explanation - by Chrilo06 - Feb-24-2022, 03:57 AM
RE: Some line code explanation - by ibreeden - Feb-24-2022, 11:16 AM
RE: Some line code explanation - by Chrilo06 - Feb-24-2022, 02:53 PM
RE: Some line code explanation - by deanhystad - Feb-24-2022, 06:24 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  New learner in Python, and need help on the term explanation BaicaiPy 3 1,346 Oct-15-2022, 03:31 PM
Last Post: Yoriz
  XOR solution explanation needed. omm 7 3,318 Oct-26-2020, 06:30 AM
Last Post: omm
  While statement explanation alkhufu2 3 2,446 Sep-02-2020, 05:46 PM
Last Post: alkhufu2
  How to repeat input line of code until condition is met Reta 2 3,428 May-14-2019, 10:06 PM
Last Post: nilamo
  Python code unable to show Bokeh line chart kirito85 2 2,563 Feb-06-2019, 07:52 AM
Last Post: kirito85
  Output explanation AmanTripathi 2 2,889 Feb-14-2018, 03:03 PM
Last Post: AmanTripathi
  need help with some explanation vincelim99 2 3,686 Mar-24-2017, 04:12 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020