Question

Using Python The variables x and y refer to numbers. Write a code segment that prompts...

Using Python

The variables x and y refer to numbers. Write a code segment that prompts the user for an arithmetic operator and prints the value obtained by applying that operator to x and y.

Using the following information run an example in Python Idle

op = input("Enter an arithmetic operator: ")

if op == "+":

    print(x + y)

elif op == "-":

    print(x – y)

elif op == "*":

    print(x * y)

elif op == "/":

    print(x / y)

else:

    print(x % y)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

RUN

CODE

EXPLANATION

x = 10

y = 4

x*y = 10*4 = 40

Add a comment
Know the answer?
Add Answer to:
Using Python The variables x and y refer to numbers. Write a code segment that prompts...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python programming Question 1: Write a script with a for loop that prints each character in...

    Python programming Question 1: Write a script with a for loop that prints each character in your first name written as first initial capital and other small, followed by its ASCII value on the screen.  Use appropriate functions to get character value to ASCII code. (Hint: Functions discussed in lectures)  For example, the output of each iteration should be as -- for ‘A’, it should print A followed by its ASCII value. Question 2: Write a script that...

  • Please use python to explain. Assume that the variables x and y refer to strings. Write...

    Please use python to explain. Assume that the variables x and y refer to strings. Write a code segment that prints these strings in alphabetical order. You should assume that they are not equal.

  • Write a PYTHON program that allows the user to navigate the lines of text in a...

    Write a PYTHON program that allows the user to navigate the lines of text in a file. The program should prompt the user for a filename and input the lines of text into a list. The program then enters a loop in which it prints the number of lines in the file and prompts the user for a line number. Actual line numbers range from 1 to the number of lines in the file. If the input is 0, the...

  • Write a code segment that prompts the user to enter a double number between (5.55 and...

    Write a code segment that prompts the user to enter a double number between (5.55 and 123.3) inclusive. If the input is invalid, print an error message and loop until the input is valid. Code in c++

  • Write a program which: - prompts the user for 2 numerical inputs - stores their two...

    Write a program which: - prompts the user for 2 numerical inputs - stores their two inputs in variables as floats - Use a while in loop to ask a user for a valid operation: (if the user's input operation isn't one of those listed above, instead print a message telling them so, and continue asking for the valid operation) - prompts the user for an arithmetic operation ( + - * / %) - stores the user's input as...

  • Using Python, write a program that prompts the user to enter their age as an integer...

    Using Python, write a program that prompts the user to enter their age as an integer and then prints out a message that says I suspect you were born in the year xxxx where "xxxx" is the current year minus the age entered. An example run where the user entered 10 for their age, would look like this: Please enter your age as an integer: 10 I suspect you were born in 2009

  • 1) Translate the following equation into a Python assignment statement 2) Write Python code that prints...

    1) Translate the following equation into a Python assignment statement 2) Write Python code that prints PLUS, MINUS, O ZERO, depending on the value stored in a variable named N. 3) What is printed by: 3 - 1 while 5: while 10 Print ) Page 1 of 9 4) Write a Python while loop that reads in integers until the user enters a negative number, then prints the sum of the numbers. 1-2 of 9 4) Write a Python while...

  • please solve using python thank you! Write a program which prompts the user to enter a...

    please solve using python thank you! Write a program which prompts the user to enter a number of rows, and prints a hollow square star pattern with 2 diagonals. Note: you can assume that the integer will always be > 1 and will be an odd number. For example: Input Result 5 Enter number of rows: 5 ***** ** ** * * * ** ** ***** 9 Enter number of rows: 9 ** ** ** * * * * *...

  • You are writing a Python script that prompts a user to guess the current contents of...

    You are writing a Python script that prompts a user to guess the current contents of a variable called temperature (assume previously set, and not shown). What is the missing statement? guess = float(input("Please enter your guess ")) ____________________________    # Fill in the missing line of code      print ("You're right!") else:      print ("Please try again") You are writing a Python script that prompts a user to guess the current contents of a variable called temperature (assume previously set,...

  • USING PYTHON - Write a program that calls a function that prompts the user to enter...

    USING PYTHON - Write a program that calls a function that prompts the user to enter a real number. The function should verify that the user entered a valid real number, and should prompt the user to re-enter any invalid input. After a valid real number has been entered, the function should return the number as a number. To test your function, from a main function, call the function two separate times and print the sum of the two numbers...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT