Help With Python Questions! For Vouches!

Status
This thread has been locked.

Blueezio

Banned
Feedback score
0
Posts
199
Reactions
38
Resources
0
The following questions will test your Python skills, please attempt as many as you can.


Write programs that do the following:


1. Takes input of two numbers and returns the following:

a. The sum of the numbers added together

b. The result of multiplying the numbers together

c. The result of dividing the first number by the second number

d. The result of subtracting the first number from the second number


2. Takes input of two numbers and return the result of dividing the larger number by the smaller number.


3. Asks the user a simple maths equation to which the user gives an answer. You then need to return if they have entered the correct or incorrect answer.


4. Take input of a list of 8 items and prints out the list.


5. Take input of a number list, which contains as many values as they choose. You then need to sort the list from smallest number to largest. You should print the list before sorting and after.
 
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

Thomas POTIER

Feedback score
0
Posts
5
Reactions
0
Resources
0
Code:
num1=input("1. Enter the first value : ")
num2=input("   Enter the second value : ")
print "a)",num1,"+",num2,"=",num1+num2
print "b)",num1,"*",num2,"=",num1*num2
print "c)",num1,"/",num2,"=",num1/num2
print "d)",num1,"-",num2,"=",num1-num2
num1=input("2. Enter the first value : ")
num2=input("   Enter the second value : ")
print(max(num1,num2)/min(num1,num2))
equ=raw_input("3. Enter a simple equation : ")
nums=equ.split(equ[1])
num1,num2,num3=tuple(nums[0])+tuple(nums[1].split("="))
num1,num2,num3=int(num1),int(num2),int(num3)
if equ[1]=="+":
    res=num1+num2
    print(num3==res)
elif equ[1]=="-":
    res=num1-num2
    print(num3==res)
elif equ[1]=="*":
    res=num1*num2
    print(num3==res)
elif equ[1]=="/":
    res=num1/num2
    print(num3==res)
print("4. Enter 8 values")
list=[]
while len(list)<8:
    list.append(input("Enter a value : "))
print(list)
maxi=input("5. Enter the number of values : ")
list=[]
while len(list)<maxi:
    list.append(input("Enter a value : "))
print(list)
list.sort()
print(list)

(Python 2.7)
 
Status
This thread has been locked.
Top