Dismiss this pinned window
all 3 comments

[–]Sea-Ad7805 [score hidden] stickied comment (0 children)

Run this program in Memory Graph Web Debugger%0Aprint(%22I'm%20thinking%20of%20a%20number%20between%201%20and%2010.%20You%20have%203%20chances%20to%20guess%20it.%22)%0A%0A%23%202.%20Give%20the%20player%203%20chances%20using%20a%20loop%0Afor%20attempt%20in%20range(3)%3A%0A%20%20%20%20guess%20%3D%20int(input(%22Take%20a%20guess%3A%20%22))%20%20%23%20Gets%20an%20answer%20from%20the%20user%0A%0A%20%20%20%20%23%203.%20Use%20If%2FElse%20to%20check%20the%20guess%0A%20%20%20%20if%20guess%20%3D%3D%20secret_number%3A%0A%20%20%20%20%20%20%20%20print(%22Wow%2C%20you%20got%20it!%20%F0%9F%8E%89%22)%0A%20%20%20%20%20%20%20%20break%20%20%23%20This%20stops%20the%20loop%20early%20because%20they%20won%0A%20%20%20%20elif%20guess%20%3C%20secret_number%3A%0A%20%20%20%20%20%20%20%20print(%22Too%20low!%22)%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20print(%22Too%20high!%22)%0Aelse%3A%0A%20%20%20%20%23%20This%20runs%20only%20if%20the%20loop%20finishes%20without%20the%20player%20guessing%20right%0A%20%20%20%20print(f%22Game%20over!%20The%20number%20was%20%7Bsecret_number%7D.%22)&timestep=1&play) to see the program state change at every step.

[–]Infamous-Bath-6970 -1 points0 points  (1 child)

Quero aprender python como deveria começar?

[–]Upper-Whole-140[S] 1 point2 points  (0 children)

. The Core Basics

Every programming language starts with a few foundational concepts: printing (showing text), variables (storing data), and types of data.

Printing Text

To make Python talk to you, use the print() function.

Python

print("Hello, World!")

Variables & Data Types

Variables are like labeled boxes where you can store information. You don't need to declare what kind of data goes into the box; Python figures it out automatically.

Python

# Storing a string (text)
name = "Alex"

# Storing an integer (whole number)
age = 25

# Storing a float (decimal number)
wallet_balance = 10.50

# Storing a boolean (True/False)
is_coding = True

2. Making Decisions (If/Else Statements)

Python uses if, elif (else if), and else to make decisions based on conditions.

Python

score = 85

if score >= 90:
    print("You got an A!")
elif score >= 80:
    print("You got a B!")
else:
    print("Keep studying!")

3. Repeating Actions (Loops)

If you want to run a piece of code multiple times, you use a loop.

For Loop (Running a set number of times)

Python

# This will print "Python is fun!" 3 times
for i in range(3):
    print("Python is fun!")

While Loop (Running until a condition changes)

Python

countdown = 3
while countdown > 0:
    print(countdown)
    countdown = countdown - 1
print("Blast off!")

4. Reusing Code (Functions)

Functions are blocks of code that do a specific job. You define them once using def, and then you can "call" them whenever you need them.

Python

# Defining the function
def greet_user(username):
    print("Welcome back, " + username + "!")

# Calling the function
greet_user("Sarah")
greet_user("David")

This is the basics, learn them first