I just started to learn python few days ago. This is a small program I made to practise.

print("Find Volumes of some Popular Solids")
print("")
names=['(1) Sphere','(2) Right Circular Cone','(3) Cylinder']
x=0
while x < 3:
    print(names[x])
    x +=1



print('\n' + 'Enter the number of the solid, you want to check the volume and press ENTER')

solid=int(input('Number : ' ))

print('\n'+'You have selected : ', (names[solid]))

x = 22/7

if solid == 1 :
    R=int(input('\n'+"Enter value for r : "))
    V=float((4*(22/7)*R) / 3)
    H=0

elif solid == 2 :

    R=int(input('\n'+"Enter value for r : "))
    H=int(input("Enter value for h : "))
    V = float((x) *(R*R) * H) * (1/3)

elif solid ==3 :

    R=int(input('\n'+"Enter value for r : "))
    H=int(input("Enter value for h : "))
    V = float((22/7)*(R*R)*H)

else :

    print("Entered value is wrong")


R=str(R)
H=str(H)
V=str(V)

print('\n'+"h = " + H + "  r = " + R)
print("Volume is : "+ V + '\n'+ '\n')

input("Press ENTER key to exit the program")

I just started to learn python few days ago. This is a small program I made to practise.

Ok,some points.

names = ['(1) Sphere','(2) Right Circular Cone','(3) Cylinder']
x=0
while x < 3:
    print(names[x])
    x +=1

This is not the way to loop in Python.
You just iterate over list like this.

names = ['(1) Sphere','(2) Right Circular Cone','(3) Cylinder']
for name in names:
    print(name)

Now all code is global space,in future think of stucture code better.
Eg using functions.

import math

def cylinder():
    '''Calculate volume of a cylinder'''
    R = int(input('\n'+"Enter value for r : "))
    H = int(input("Enter value for h : "))
    result = math.pi * (R*R) * H
    return result

Test.

>>> cylinder()
Enter value for r : 5
Enter value for h : 10
785.3981633974483

>>> help(cylinder)
Help on function cylinder in module __main__:

cylinder()
    Calculate volume of a cylinder

So you could had have 3 functions,this mean that code is isolatet in function.
As you see it help readability of code,and code reuse(you can now put this function in other code and call it).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.