Python - Random numbers and choices

preview_player
Показать описание
Learn Python - Take our Python class for free! This python course for beginners consists of 10 classes, slowly and progressively introducing Python skills through explanations, example walk-throughs and code challenges. We know that the best way to learn Python is to start practising. In this sixth instalment we look at how to generate random numbers and select random items from lists.

00:00 Introduction

Code repository for this course:
Find all the code demonstrated, including code Challenges

Python Beginners Course Structure:
001 – Print, Variables and Simple Data Types
002 – Python Inputs
003 – If..elif..Else Statements
004 – String Manipulation
005 – Python Maths
006 – Random
007 – Tuples, Lists and Dictionaries
008 – For Loops
009 – While Loops
010 – Functions

🐱‍🏍Would you like to SUPPORT US FURTHER so that we can make even more great content - Please consider joining our members community.

👍SUBSCRIBE to get more free tutorials, courses and code snippets!
Рекомендации по теме
Комментарии
Автор

wow so thorough even explaining what rock paper scissors is, thank U

oldphotos
Автор

Challenge 1

x = random.randint(1, 100)
y = input("Enter a random integer from 1 to 99: ")

try:
y == int(y)
except ValueError:
print("Input must be an integer")
if y == x:
print("You've won!")
else:
print("Try again")
print(f"your guess={y}, my guess={x}")

ademolasorungbe
Автор

Thanks, greats, and good job zander..

dadan.dahman.w
Автор

one = int(input("Enter: "))

two = int(input("Enter: "))

three = int(input("Enter: "))

four = int(input("Enter: "))

lottery = [one, two, three, four]

x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]

calc = random.sample(x, 4)

print(*calc)

if lottery == calc:

    print(f"YES!!! You got the lucky lottery numbers: {calc}")

else:

    print(f"Sorry your input {lottery} does not match the lucky numbers, try again")

creativecraft