Prompt:
“Take original = [1, 2, 3, 4, 5] and create a new list squared where each number is squared. Then print squared. Do not use a traditional for loop.”
Answer:
original = [1, 2, 3, 4, 5]
squared = [x**2 for x in original]
print(squared)
Output: [1, 4, 9, 16, 25]
Pros:
Cons:
So, you’ve conquered the basics. You’ve mastered print("Hello World") and you understand how variables work. Now, you’ve stepped into Code Avengers Python Level 2, and things are getting a little more complex.
Level 2 shifts from simple commands to the core logic of programming: Control Flow. This is where you learn how to make your code "think" and repeat actions. code avengers answers python 2 new
If you’re stuck on a specific lesson or just need a nudge in the right direction, this guide covers the key concepts you'll encounter in Python 2 and provides sample solutions to common types of problems.
This is how your program makes decisions. Prompt: “Take original = [1, 2, 3, 4,
Sample Question:
Write a program that checks if a variable age is 18 or older. If yes, print "Adult". Otherwise, print "Minor".
Solution:
if age >= 18:
print("Adult")
else:
print("Minor")