Python User Input & Control Flow | Python tutorial

preview_player
Показать описание

Learn Python user input & control flow in this Python tutorial. You will learn how to receive user input and apply control flow to a simple game that will determine who wins and what is output.

⭐ Become a full-stack dev with Zero To Mastery Courses:

👇 Follow Me On Social Media:

Python User Input & Control Flow 🐍

(00:00) Intro
(00:05) Welcome
(00:18) Create a new file
(00:33) Basic User Input
(02:46) Basic Control Flow
(06:19) Exiting the program
(07:01) User Input Data Type
(08:17) Random Computer Choice
(09:23) Output the choices
(10:53) Game Winner Control Flow
(13:55) Test the Game
(14:26) Improving the Game
(15:44) Introducing Enums
(20:02) Improve the Game with Enums

Corrections:
(5:53) The pipe symbol is a bitwise OR.. but not what we needed here. We just need the word "or". I have updated the source code for the lesson with this correction. 🚀

📚 Tutorial References:

Was this Python User Input and Control Flow tutorial for beginners helpful? If so, please share. Let me know your thoughts in the comments.

#python #user #input
Рекомендации по теме
Комментарии
Автор

Love the length of these videos; i feel like many python tutorials are hours long which can be kind of daunting! keeping each video on a few topics makes it much easier to take on. thanks!

burgeronus
Автор

Thank you so much, you are single handedly teaching me python in a very user friendly and simple way.

itsaak
Автор

These vidoes are awesome, thanks for making them Dave!

hannaingrín
Автор

Thanks a ton for making these videos Dave.

juanmayen
Автор

Now my class start learning Python, these lessons help me a lot.

ClashOfMedias
Автор

THANK YOU FOR MAKING MY LEARNING SO EASY WITH YOUR GREAT EXPLANATIONS DAVE 👍👍

ashishranjan
Автор

Hi Dave, thank you for these videos, I have watched your tutorials on HTML, CSS, Javascript, React (not-finished) and Next.js. You are the best. For improving the game code, can I re-write the code as:
*
if player == 1:
player = "Rock"
elif player == 2:
player = "Paper"
else:
player = "Scissors"
*
instead of importing Enum? obviously you will do it for computer and then print("You chose " + player + ".")
print("Python chose " + computer + ".")

bensonibeabuchi
Автор

You are very good. You are EXCELLENT! Love from SINGAPORE

adamcylee
Автор

For those who are running into problems:
Just replace the "|" with "or"

Microwaveoficial
Автор

Great series Dave 🔥
Definitely good to take a JS every now and then.
Let’s see how far you take us!

doors
Автор

Nice video. Please upload video regularly plzzz dev. And thanks for your amazing content as always.

anirudh
Автор

Excellent video!
I did have trouble triggering the 'exit' if statement for invalid player entries though.
It seems the pipe no longer works as an 'or' operator in Python 3.12.0. I got the statement to trigger by simply using 'or' instead of the pipe.

anthonyythomas
Автор

I got a problem. The mini-game works when I run it through the play button and type 1, 2 or 3. It wont work when I type 1, 2 or 3 in the terminal. It will just return whatever number i typed. If I type 2, it will just return the number 2 etc.

cookie
Автор

I have a question re: the use of Enum.
could you also use a list for the Rock, Paper, Scissors? eg:
pieces = ["Rock", "Paper", "Scissors"]
and then refer to them on line 26 as: print("You chose " + pieces[player-1] + ".")
(the -1 is needed since a list index begins at 0, not 1.
Just a thought.

Not-THAT-ChrisPratt
Автор

When I enter any 3 numbers in the terminal(1 for rock, 2 for scissors, 3 for paper) nothing happens. I am not sure what the issue is. Can anyone help?

ColombianCatastrophe
Автор

Awesome tutorial! Thank you so much. 1 question: is RPS(player).name not much simplier that replace, or am i missing something?

Blonar
Автор

Hey Dave, thanks you for the contents and education, I have been learning a lot from all your videos. Please can you also teach us something about using react animation packages like react spring? I have been trying to read the docs and wrap my head around it, but everything seems complicated.

antwierasmus
Автор

Hey Dave, thanks for making these videos. I want to know if u want to continue the RPS game (that the program should not end and again ask for input value) what command can be used for this.

nishantsingh
Автор

When I enter 2 for my choice and press enter it only just takes me back to another prompt but it doesn’t tell me what I selected vs what the computer selected. What is the issue? 10:48

appendix-qk
Автор

12:19 i like python a lot. But i don't like the keyword `elif`. Why did they call it that? It's inconsistent. If you're going to say elif for elseif, then you should say el for else.

johnaweiss