Python Lab 2a: Input and output 1. Ask the user to enter their name. Then say hello and repeat their name. 2. Ask the user to enter their age. Print out their age 5 years from now. 3. Use concatenation and str() to print a message telling the user how old they will be in 5 years. 4. Ask the user to enter in values that might be floating point. 5. Print out the result of the calculation in a single print statement, using concatenation. 6. If Time In Python, the input() function is used to accept input. The result is stored as a string type. name = input ('what is your name?") print ('Hello + name) ' To be able to add 5 to the user input, it has to be converted to an integer. x= int(input (what is your age?") print (x + 5) When you are printing out a string message and want to concatenate a number onto the string, use str() to convert a numeric value to a string. If the user entered 27, your output should be similar to the following: In 5 years you will be 32 years old Let's calculate the amount of pay an hourly worker will get for working in a week. Ask the user to enter in the number of hours worked, convert this to a floating point value, and store this in a variable. Enter the number of hours worked: 33.7 Ask the user to enter in their hourly wage, but not with the $, convert this to a floating point value, and store the result in a variable. Enter your hourly wage, without the $: 11.32 Calculate their weekly paycheck and print out a message, using one print statement, and using concatenation. Your gross pay this week is $ 381.484 If you have time, search on the web for a way to round to 2 decimal places. Change your output to show just 2 places after the decimal.
Operations
In mathematics and computer science, an operation is an event that is carried out to satisfy a given task. Basic operations of a computer system are input, processing, output, storage, and control.
Basic Operators
An operator is a symbol that indicates an operation to be performed. We are familiar with operators in mathematics; operators used in computer programming are—in many ways—similar to mathematical operators.
Division Operator
We all learnt about division—and the division operator—in school. You probably know of both these symbols as representing division:
Modulus Operator
Modulus can be represented either as (mod or modulo) in computing operation. Modulus comes under arithmetic operations. Any number or variable which produces absolute value is modulus functionality. Magnitude of any function is totally changed by modulo operator as it changes even negative value to positive.
Operators
In the realm of programming, operators refer to the symbols that perform some function. They are tasked with instructing the compiler on the type of action that needs to be performed on the values passed as operands. Operators can be used in mathematical formulas and equations. In programming languages like Python, C, and Java, a variety of operators are defined.
Step by step
Solved in 3 steps with 6 images