Learn Python Programming - 19 - Conditionals and Control Flow

preview_player
Показать описание
Let's cover conditionals and control flow! This includes your boolean logic combined with boolean operators combined with if then type of statements! ...
...
★☆★ FREE Lesson 1: The Most Important Thing For a Successful Programmer★☆★

Enroll for coding exercises, projects, tutorials, and courses...
Clever Programmer
Snapchat ► Rafeh1
Рекомендации по теме
Комментарии
Автор

Man this guy is 110 time better than my programming teacher. I wish saw these videos last year.

khubaibmohamed
Автор

Worthy video even after 4 years man!!!

mr_bean
Автор

The way this guys cursor is going to make someone go crazy ! *_$

fromme
Автор

Once you get the gist of the video, I encourage trying to make a Choose Your Own Adventure game. From start to end, you'll encounter various scenarios and you'll have choices to make that lead you to the right path. I've done this before and it was fun getting it to work. It was also my first Python 3 game. I'll see if I can find and post it on my Github at some point.

stellarestuary
Автор

Great tutorials. I have a suggestion, maybe you could try this instead:

computer = input('Enter your choice wisely (computer): ')
if computer != ('rock' or 'paper' or 'scissors'):
print("FAIL!")
else:
print("SUCCESS!")

machine = input('Do it one more time (machine): ')
if machine == 'rock' or 'paper' or 'scissors':
print("SUCCESS!")
else:
print("FAIL!")

'machine' can be asked with an AND operator also, yet I do not know if there is a subtle difference with OR and how important it is.

on the other hand, 'computer', if asked for logic without parenthesis, gives always FAIL as an answer. the other way is to code it as you did, with an ANDs, and without parenthesis.

Keep it coming :D
All the best.

dragonknight
Автор

if (rock and scissor) or (scissor and rock):
print("ROCK")
elif (scissor and paper) or (paper and scissor):
print("SCISSOR")
elif (rock and paper) or (paper and rock):
print("PAPER")
else:
print("WRONG CHOICE")

pytechsolutions
Автор

What is the reason why you are interested in scheme rather than other languages?

adhdcartoon
Автор

You made a mistake, at 5:50 yoy said you get not(True or True), but you actually get not(True or not(True)) which means not (True or False). This still gives not(True) = False, but just wanted to point it out if someone got confused.

georgesoulantikas
Автор

i made a reverser so whtever u put in iwill reverse it
reverser=input('Enter to reverses pls:')
print(giberize[::-1])

abdulrr-wmvp
Автор

Hey Im new to your Python series and I wanted to share my code for the rock, paper .... game
dont expect to much Im new to it!xD

#Schere, Stein, Papier: DAS SPIEL

#IMPORT and initialize variables

import random
human_points = 0
CPU_points = 0

#Entscheudungsmöglichkeiten

Tools = ["Schere", "Stein", "Papier"]

#Auswahl

human = "Papier" #


#Erroranzeige

if human != "Schere" and human != "Papier" and human != "Stein" :
print("Auswahl steht nicht zur Verfügung")

else :
#COMPUTER AUSWAHL

print("CPU AUSWAHL :")
print(random.choice(Tools))

CPU = random.choice(Tools)

#SIEGERAUSWAHL-SYSTEM

if (human == "Schere" and CPU == "Papier") or (human == "Stein" and CPU == "Schere") or (human == "Papier" and CPU == "Stein") :
human_points = human_points + 1
print("YOU WON!!!")

elif (CPU == "Schere" and human == "Papier") or (CPU == "Stein" and human == "Schere") or (CPU == "Papier" and human == "Stein"):
CPU_points = CPU_points + 1
print("YOU LOST!!!")

if (human == "Schere" and CPU == "Schere") or (human == "Stein" and CPU == "Stein") or (human == "Papier" and CPU == "Papier") :
print("DRAW!!!")

#Punkteausgabe

print(human_points)
print(CPU_points)


The comments are on german because Im from Germany
I would be very thankful if you tell me how it is

omerturan
Автор

am lovin it
I did a simple rock paper scissors game through python


player1='
player2='


#This function depends on the players choise
#rock paper or scissors



if player1=='rock' and player2=='scissors':
print('player 1 has won')
elif player1=='scissors' and player2=='rock':
print('player2 has won')
elif player1=='rock' and player2=='paper':
print('player2 has won')
elif player1=='paper' and player2=='rock':
print('player 1 has won')
elif player1=='scissors' and player2=='paper':
print('player1 has won')
elif player1=='paper' and player2=='scissors':
print('player2 has won')
elif player1 or player2 != 'rock' or 'scissors' or 'paper':
print('you cant choose other than rock paper or scissors')

kakalukium
Автор

Bro please answer this What is the difference between code academy tutorial and this(learn python programming) tutorial ??

sarveshgupta
Автор

Hey Qazi, what did I do wrong? Was messing around with things I found online. Computer and human score should both be 1, but both come up as 3...


human = 'rock', 'paper', 'scissors'
computer = 'rock', 'paper', 'scissors'

computer_score = 0
human_score = 0

if computer[0] and human[2]:
computer_score += 1

if computer[1] and human[0]:
computer_score += 1

if computer[2] and human[1]:
computer_score += 1


if human[1] and computer[0]:
human_score += 1

if human[2] and computer[1]:
human_score += 1

if human[0] and computer[2]:
human_score += 1



print(computer[0])
print(human[2])

print(computer[2])
print(human[0])

print(human_score)
print(computer_score)

andrewpickett
Автор

What is wrong in this codes: var =input('here') varea= 100 print(" ") if var == varea: print('hello') print(var) else: print('bye') print(var).

virtualworldofnepal
Автор

why did it print? the if statement is false and false and false which results to false! Please clarify. Thanks.

animalslife
Автор

def rock_paper_scissors():
import random
import time
pick = random.choice(["rock", "scissors", "paper"])
pick1 = input("Choose one of the following. Rock, paper or scissors!(remember to only use small characters): ")
while pick1 != "rock" and pick1 != "scissors" and pick1 != "paper":
pick1=input("You didn't write either rock, paper or scissors. Maybe you forgot to do it in small charcters. Do it again here: ")
time.sleep(.5)
print("Computer's "+str(pick))
time.sleep(.5)
print("Your "+str(pick1))
time.sleep(1)
if str(pick)==("scissors")and str(pick1)==("rock"):
print("You won")
elif str(pick)==("scissors")and str(pick1)==("paper"):
print ("You lost")
elif str(pick)==("scissors")and str(pick1)==("scissors"):
print("It's a tie")

if str(pick)==("rock")and str(pick1)==("paper"):
print("You won")
elif str(pick)==("rock")and str(pick1)==("scissors"):
print ("You lost")
elif str(pick)==("rock")and str(pick1)==("rock"):
print("It's a tie")

if str(pick)==("paper")and str(pick1)==("scissors"):
print("You won")
elif str(pick)==("paper")and str(pick1)==("rock"):
print ("You lost")
elif str(pick)==("paper")and str(pick1)==("paper"):
print("It's a tie")
time.sleep(4)
print("Restart inc")
while True:
import time
rock_paper_scissors()
time.sleep(2)
Let me know what you think. I know it could be done shorter but i think its good!

God-gqeg
Автор

Very very simple game of rock paper scissors! I didn't go too much into it and it barely took me like 15 minutes! Try it yourself and please suggest some changes!

#ROCK, PAPER, SCISSOR GAME:

human = '#YOUR CHOICE HERE'
computer = '#YOUR CHOICE HERE'

if human == 'ROCK' and computer == 'ROCK':
print('DRAW')
elif human == 'PAPER' and computer == 'PAPER':
print('DRAW')
elif human == 'SCISSOR' and computer == 'SCISSOR':
print('DRAW')
elif human == 'ROCK' and computer == 'PAPER':
print('COMPUTER WON')
elif human == 'PAPER' and computer == 'ROCK':
print('HUMAN WON')
elif human == 'ROCK' and computer == 'SCISSOR':
print('HUMAN WON')
elif human == 'SCISSOR' and computer == 'ROCK':
print('COMPUTER WON')
elif human == 'PAPER' and computer == 'SCISSOR':
print('COMPUTER WON')
elif human == 'SCISSOR' and computer == 'PAPER':
print('HUMAN WON')
elif human != 'PAPER' and human != 'ROCK' and human != 'SCISSOR':
print('INVALID! TRY AGAIN')
elif computer != 'PAPER' and computer != 'ROCK' and computer != 'SCISSOR':
print('INVALID! TRY AGAIN')

nihalahmed
Автор

What Am I doing Wrong?

if hugo_hasID and hugo_age >18:
hugo = True
print ("he can enter")
elif hugo_forgot_his_shoes:
hugo = False
print ("denied")

"he can enter"

I want this to print "Denied" !.

hugomoralesg
Автор

Can I have a question? Why are you learing Scheme? :O Thank you for the videos :)

krhi
Автор

There's something I don't understand
High _income=False
good_credit= True
Student= False
If (high_income or good credit) and not student:
Print("eligible")
else:
Print("not eligible")
Am getting eligible
I was expecting not eligible
I don't understand

emeldaoluoch