Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Can I Do Anything more to make it 100 percent efficient ? (python_3)

+1 vote
asked Mar 10, 2020 by Emmanuel Fernandes (140 points)
def speed():
    q  = input('\nwhat do you want to work out using the speed formula?\n')
    q=q.upper()
    if q==('SPEED'):
        M = int(input('what is the distance?in (Meters)\n'))
        D=M
        X = int(input('\nwhat is the time?(mins)\n'))
        T=X
        S=D/T
        print('the speed is:', S+'Meters per min')
        S=0
        D=0
        T=0
    if q==('TIME'):
        M1 = int(input('what is the speed?(mpm)#meters per min\n'))
        S=M1
        X1 = int(input('what is the distance?(meters)\n'))
        D=X1
        T=S/D
        print('the tme is\n',T+'Minutes')
        S=0
        D=0
        T=0
    if q==('DISTANCE'):
        M2 = int(input('what is the speed?#meters per min\n'))
        S=M2
        X2 = int(input('What is the time?(mins)\n'))
        T=X2
        D=s/T
        print('the distance is:\n',D+'Meters')
        S=0
        D=0
        T=0
    else:
        speed()

R=0#RADIUS
H=0#HEIGHT
S=0
D=0
T=0

C = int(input('Enter radius of cylinder:\n'))
R=C

Z = int(input('Enter height of cylinder:\n'))
H=Z

V=(3.14159*R*R*H)#EQUATION FOR VOLUME OF CYLINDER
A=(3.14159*2*R*R)+(2*3.14159*R*H)#EQUATION FOR SURFACE AREA OF CYLINDER
print('the volume of the cylinder is :\n',V)
print('the area of the cylinder is:\n',A)
speed()

1 Answer

0 votes
answered Mar 12, 2020 by Andy Peerez (140 points)
Hi
you can still make it more efficient with the libraries offered by python, I recommend them :)

import math
def speed():
    q  = input('\nwhat do you want to work out using the speed formula?\n')
    q=q.upper()
    if q==('SPEED'):
        M = int(input('what is the distance?in (Meters)\n'))
        X = int(input('\nwhat is the time?(mins)\n'))
        S=M/X
        print('the speed is:', S, 'Meters per min')
    if q==('TIME'):
        M1 = int(input('what is the speed?(mpm)#meters per min\n'))
        X1 = int(input('what is the distance?(meters)\n'))
        T=M1/X1
        print('the tme is\n',T,'Minutes')
    if q==('DISTANCE'):
        M2 = int(input('what is the speed?#meters per min\n'))
        X2 = int(input('What is the time?(mins)\n'))
        D=M2/X2
        print('the distance is:\n',D+'Meters')
    else:
        speed()

R = int(input('Enter radius of cylinder:\n'))
H = int(input('Enter height of cylinder:\n'))

V=(math.pi*R*R*H)#EQUATION FOR VOLUME OF CYLINDER
A=(math.pi*2*R*R)+(2*3.14159*R*H)#EQUATION FOR SURFACE AREA OF CYLINDER
print('the volume of the cylinder is :\n',V)
print('the area of the cylinder is:\n',A)
speed()

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...