PYTHON LESSON

Topic 4/63 · Phase 1: Foundations

Type Casting — Python lesson on EduBard (phase: Foundations)

Type Casting

Main idea

Casting converts values into the required data type.

Tip

Cast user input immediately.

Watch out

Converting invalid text to int without checks.

Read this next

You will study Type Casting. It belongs to the Foundations phase.

Remember this:
Casting converts values into the required data type.

Practice step by step. Do not rush. Each run should show you something new.

Tip:
Cast user input immediately.

Avoid this:
Converting invalid text to int without checks.

Your challenge:
Take two string numbers, convert, and print the sum.

Go to the challenge lab below. Fix errors until the output looks right. Then press the green button to complete the topic.

Example code

Copy this example if it helps. Change it so it matches Type Casting.

# Topic: Type Casting
def main():
    sample = "edit me"
    # TODO: apply Type Casting concept here
    result = sample
    print("Result:", result)

if __name__ == "__main__":
    main()

Challenge

Take two string numbers, convert, and print the sum.

Before you can finish: your output should include at least 14 characters; at least 1 non-empty line(s); no crash traceback—fix errors until the program runs cleanly.

Use Run. Read the output. Change your code until the task is done.

Starter reference

# Challenge starter for Type Casting
def solve():
    # Write your solution here
    pass

print("Update solve() and run")

Your code

The first Run may load Python in your browser (one-time). Later runs are faster.



    
    

Navigation