1.12 Ch 1 Warm up: Basic output with variables (Python 3) This zyLab activity pr
ID: 3742014 • Letter: 1
Question
1.12 Ch 1 Warm up: Basic output with variables (Python 3)
This zyLab activity prepares a student for a full programming assignment. Warm up exercises are typically simpler and worth fewer points than a full programming assignment, and are well-suited for an in-person scheduled lab meeting or as self-practice.
A variable like userNum can store a value like an integer. Extend the given program to print userNum values as indicated. (Submit for 2 points).
(1) Output the user's input.
Note: This zyLab outputs a newline after each user-input prompt. For convenience in the examples below, the user's input value is shown on the next line, but such values don't actually appear as output when the program runs.
(2) Extend to output the input squared and cubed. Hint: Compute squared as userNum * userNum. (Submit for 2 points, so 4 points total).
(3) Extend to get a second user input into userNum2. Output sum and product. (Submit for 1 point, so 5 points total).
Explanation / Answer
userNum = int(input('Enter integer: ')) print('You entered: %d' % userNum) print('%d squared is %d' % (userNum, userNum*userNum)) print('And %d cubed is %d !!' % (userNum, userNum*userNum*userNum)) userNum2 = int(input('Enter another integer: ')) print('%d + %d is %d' % (userNum, userNum2, userNum+userNum2)) print('%d * %d is %d' % (userNum, userNum2, userNum*userNum2))
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.