if you need to keep something inside memory, like a word, you’ll create a VARIABLE
here my VAR is called A, but Type Of is A STRING
myVar=”toto”
if you need to keep something inside memory, like a number, you’ll create a VARIABLE
here my VAR is called A, , but Type Of is A INTEGER
myVar=2
True/False type bool
if you need to keep inside memory 2 differents numbers, for example, you’ll make a TUPLE
here my VAR is called myVar, , but Type Of is A TUPPLE
myVar=[(360,34)] #INTEGER Case
myVar=[(“toto”,”raj”)] #STRING Case
myVar=[(360,”isTheMax”)] #MIXED Case
if you need to organise a more complex data, you should use a TAB??
here my VAR is called myVar, , but Type Of is A TAB
myVar=[(2,8);(150,34);(3,6);etc…]
please note that a tab should have many dimensions, for example, an 2D TAB looks like this :
MATRIX
MATRIX
MATRIX
if you need to keep a PROCESS( i mean a bit CODE) inside a memory, you will use a FONCTION :
here my VAR is NOT a Variable, , but Type Of is FONCTION
def myFfunction(arg1, arg2, etc..) #you will provide the fonction with arguments, like Variables or Tupples, etc..
Make the job…
return (parameter1,p2, etc) #OR NOTHING!! YOUR Fonction can return Elements like variables, or tupples, etc..
if your need to inject code AND arguments in the same thing, you have to create an OBJECT :
here my VAR is NOT a Variable, , but Type Of is an OBJECT
Class(ETC…)
PLEASE MIND FOR EACH ELEMENT (variable, tupple, fonctions and class) You have to Give A GoodName like:
myVAR= hightSensor OR my_List= listOfParam, myProcess= DeletingProc(args1,arg2), myClass= MainSystem, …)
Keep in mind that CAPS (on main words) is nice to give name for reading, and cleaning your code as well 😉
import random
userAction = input(“Enter a choice (rock, paper, scissors): “)
possibleActions = [“rock”, “paper”, “scissors”]
Â
Â
#make a random for the computer choice
computerAction = random.choice(possibleActions)
Â
#print the battle
print(f”\nYou chose “+userAction+”, computer chose “+computerAction+”\n”)
#Determine the winner cases by cases
#if match is over
if userAction == computerAction:
print(f”Both players selected {userAction}. It’s a tie!”)
#2 cases if user have choosen rock
elif userAction == “rock”:
if computerAction == “scissors”:
print(“Rock smashes scissors! You win!”)
else:
print(“Paper covers rock! You lose.”)
#Test the program to determine if there’s other cases to manage
import random
userAction = input(“Enter a choice (rock, paper, scissors): “)
possibleActions = [“rock”, “paper”, “scissors”]
#make a random for the computer choice
computerAction = random.choice(possibleActions)
#print the battle
print(f”\nYou chose “+userAction+”, computer chose “+computerAction+”\n”)
#Determine the winner cases by cases
#if match is over
if userAction == computerAction:
print(f”Both players selected {userAction}. It’s a tie!”)
#2 cases if user have choosen rock
elif userAction == “rock”:
if computerAction == “scissors”:
print(“Rock smashes scissors! You win!”)
else:
print(“Paper covers rock! You lose.”)
#2 cases if user have choosen paper
elif userAction == “paper”:
if computerAction == “rock”:
print(“Paper covers rock! You win!”)
else:
print(“Scissors cuts paper! You lose.”)
#2 cases if user have choosen scissors
elif userAction == “scissors”:
if computerAction == “paper”:
print(“Scissors cuts paper! You win!”)
else:
print(“Rock smashes scissors! You lose.”)