Uploaded by vivar006

PYTHON

advertisement
PYTHON practice
https://replit.com/languages/python3
RANDOMLY SELECT A CARD
import random
def pick_a_card():
card_suit=['diamond','spaces','heart','clubs']
card_rank=['1','2','3','4','5','6','7','8','9','10']
print(card_suit)
print(card_rank)
random_suit=random.choice(card_suit)
random_rank=random.choice(card_rank)
print(random_suit)
print(random_rank)
pick_a_card()
RANDOMLY SELECT A NUMBER
import random
def pick_a_number():
random_selection=['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23
','24','25','26','27','28','29','30', '31', '32', '33']
random_rank=random.choice(random_selection)
print(random_rank)
pick_a_number()
https://replit.com/languages/python3
Randomly select a group 1 and randomly select a group 2
import random
def pick_a_card():
GROUP_ONE=['group_a','group_b','group_c','group_d']
GROUP_TWO=['1','2','3','4','5','6','7','8','9','10']
random_group_one=random.choice(GROUP_ONE)
random_group_two=random.choice(GROUP_TWO)
print(random_group_one)
print(random_group_two)
pick_a_card()
Console: output from the code
Command:
print(‘enter something’)
Variable: Name for stored value in our code.
my_var = 7
Integer: whole numbers, and strings are text. Strings are written with as following
Strings are text written with quotes
my_int = 14
my_str = “fifteen”
Variable cannot:
Containt spaces
Start with a number
Contain any symbols
Variable can:
Capital letters
Lower case letters
Digits (cannot start with digits)
Imderscores
Python lists: A list can contain multiple values. List are denoted by square brackets, and values are
separated by commas within them as below. Spaces are not necessary but are helpful for readability.
[5,”orange”,”home”,97]
List can also be assigned to variables:
my_story= "I am a undergraduate student who is seen as an international student. However, I am not
an international student and have been in the USA since I was 10."
Color=[‘orange’,’pink’,’red’]
Numbers=[89,10,1000]
Python printing: will display something in the console
status= 'stateless individuals and daca recipients'
print(fav_animal)
You can use a special string called an f-string to make formatted text that includes variables by
wrapping the variables with curly brackets.
print(f'my love for {status} is the following story: {my_story}')
Python Libraries: a library is an extension for python that gives quick access to functions and codes for
specific tasks.
important random (this is a library called random)
my_color="orange"
my_story= "I am a undergraduate student who is seen as an international student. However, I am not
an international student and have been in the USA since I was 10."
my_state="minnesota"
my_int=5
[3, 'no', 'yellow']
colors=['green','red','blue','orange']
my_list= [3, 'no', 'yellow', 10]
Numbers=[89,10,1000]
print('does this work?')
fav_animal= 'stingray'
print(fav_animal)
status= 'stateless individuals and daca recipients'
print(my_color)
print(my_story)
card_list=["diamonds", "heart", "clubs", "spaces"]
print(my_list)
print(f'my love for {fav_animal} is the following story: {my_story}')
print(f'my love for {status} is the following story: {my_story}')
import random
random_color=random.choice(colors)
print(random.choice(colors))
print(random_color)
random_suit=random.choice(card_list)
print(random_suit)
print(f'we will use the random colors here: {random_color}, the color that was just labeled was
generated by the code using python')
def pick_a_color():
colors=['green','red','blue','orange']
random_color=random.choice(colors)
print(f'we will use the random colors here: {random_color}, the color that was just labeled was
generated by the code using python')
pick_a_color()
import random
card_suit=['diamond','spaces','heart','clubs']
card_rank=['1','2','3','4','5','6','7','8','9','10']
print(card_suit)
print(card_rank)
random_suit=random.choice(card_suit)
random_rank=random.choice(card_rank)
print(random_suit)
print(random_rank)
RANDOMLY SELECT A CARD
import random
def pick_a_card():
card_suit=['diamond','spaces','heart','clubs']
card_rank=['1','2','3','4','5','6','7','8','9','10']
print(card_suit)
print(card_rank)
random_suit=random.choice(card_suit)
random_rank=random.choice(card_rank)
print(random_suit)
print(random_rank)
pick_a_card()
RANDOMLY SELECT A NUMBER
import random
def pick_a_number():
random_selection=['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23
','24','25','26','27','28','29','30', '31', '32', '33']
random_rank=random.choice(random_selection)
print(random_rank)
pick_a_number()
Download