Question

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 prompts the user to enter values for variable x and variable y, and an arithmetic operator to be applied on x and y.

 The script will continuously run unless interrupt by the user.

 Based on the arithmetic operator, prints the value obtained by applying that operator to x and y. (use an infinite loop and use if-elif-else construct)

0 0
Add a comment Improve this question Transcribed image text
Answer #1
# Question 1
name = input("Enter name: ")
name = name[0].upper() + name[1:]
print("Name:",name)
print("-------------------")
print("Character\tASCII")
print("-------------------")
for x in name:
    print(x,"\t\t\t",ord(x))

################################

# Question 2
def sum(x,y):
    return x+y

def diff(x,y):
    return x-y

def mul(x,y):
    return x*y

def div(x,y):
    return x//y

def mod(x,y):
    return x%y

def power(x,y):
    return x**y

def main():
    while(True):
        x = eval(input("Enter number1 : "))
        y = eval(input("Enter number1 : "))
        print("1. add\n2. subtract\n3. Multiply\n4. Divide\n5. Reminder\n6. Power\nEnter your choice: ")
        n = eval(input())
        if(n == 1):
            print("Answer:",end="")
            print(sum(x,y))
        elif(n == 2):
            print("Answer:", end="")
            print(diff(x,y))
        elif(n == 3):
            print("Answer:", end="")
            print(mul(x,y))
        elif (n == 4):
            print("Answer:", end="")
            print(div(x, y))
        elif(n == 5):
            print("Answer:", end="")
            print(mod(x,y))
        elif(n == 6):
            print("Answer:", end="")
            print(power(x,y))
        else:
            print("Invalid choice")
            break

main()

Add a comment
Know the answer?
Add Answer to:
Python programming Question 1: Write a script with a for loop that prints each character in...
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
  • 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 == "/":...

  • 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...

  • I need help with this python programming exercise, please! thanks in advance Create a Python script...

    I need help with this python programming exercise, please! thanks in advance Create a Python script file called hw4.py. Add your name at the top as a comment, along with the class name and date. Both exercises should be in this file, with a comment before each of them to mark it. Ex. 1. Write a program that inputs an integer number from the user, then prints a letter "O" in ASCII art using a width of 5 and the...

  • On question 1-3 can you please answer each script separately. Please Use Perl Scripting 1. write...

    On question 1-3 can you please answer each script separately. Please Use Perl Scripting 1. write a program that computes the circumference of a circle with a radius of 12.5. Circumference is 2π times the radius (approximately 2 times 3.141592654). The answer you get should be about 78.5. 2. Modify the program from the previous exercise to prompt for and accept a radius from the person running the program So, if the user enters 12.5 for the radius, she should...

  • Kjell, Chapter 26, Exercise 1 — Arithmetic Expression Write a subroutine that takes three arguments, A,...

    Kjell, Chapter 26, Exercise 1 — Arithmetic Expression Write a subroutine that takes three arguments, A, X, and Y. It then computes A*X*Y and returns it. Use the subroutine to evaluate the following for various values of u and v: 5u2 - 12uv + 6v2 The main method, in a loop, prompts the user for values of u and v and prints out the result. End the loop when the user enters zero for both u and v.

  • 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 Python script in that will prompt the user to enter a string. After the...

    Write a Python script in that will prompt the user to enter a string. After the user enters their string print its length and the ordinal value of the first, third, and seventh character. Assume the input will be of sufficient length. Use "nice" input and output

  • Python Programming language Write the following functions: getNumInRange(prompt, min, max) - get...

    Python Programming language Write the following functions: getNumInRange(prompt, min, max) - gets a number from the user within the specified range, prompting with 'prompt' calcAvg(values) - calculates and returns the average from a supplied list of numeric values menu(somelist) - creates a numbered menu from a list of strings. Then, have the user select a valid choice (number), and return it. Use the getNumInRange() funtion to do this. getAlbum() - prompts the user for information to populate a dictionary representing...

  • 4) (12 points) Write the CH code that continuously (use a loop) prompts a user to...

    4) (12 points) Write the CH code that continuously (use a loop) prompts a user to input a floating point number. Each time, the code prints out the input, numbered. So if the user inputs a -2.3 for the first input and a 116.79 for the second input, the output is input 1: -2.3 input 2: 116.79 The loop keeps running until the sum of all the numbers input is greater than 100. (This needs an accumulator!)

  • Part 1: Using Idle Write a Python Script that Does the Following 1. At the top...

    Part 1: Using Idle Write a Python Script that Does the Following 1. At the top of your program, import the math library as in from math import * to make the functions in the math module available. Create a variable and assign into it a constant positive integer number of your choice. The number should be at most 10. 1 Suppose we call this variable x for this writeup document Try something like x = 4 2. Create another...

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