-1

Write a program in python program to find sum or product when you press s it will find sum and when you will press p find product.if you entered other character it will print you entered wrong character.ch value is not comparing with s or p.error s is not defined

a = input("enter a number\n")
b = input("enter a number\n")
c = input("enter a number\n")
print "enter s for sum and p for product"
ch = input("enter character")
if(ch=='s'):
    s = a+b+c
    print "the product of the number:" +s
elif(ch =='p'):
    p = a*b*c
    print "the product of the number:" +p
else:
    print "entered invalid character"

This code giving

Name error: name 's' is not defined

martineau
  • 119,623
  • 25
  • 170
  • 301
Manjot Singh
  • 33
  • 1
  • 7

1 Answers1

0

Use raw_input for read string from input.

a = input("enter a number\n")
b = input("enter a number\n")
c = input("enter a number\n")
print "enter s for sum and p for product"
ch = raw_input("enter character")
if(ch=='s'):
    s = a+b+c
    print "the product of the number:" +str(s)
elif(ch =='p'):
    p = a*b*c
    print "the product of the number:" +str(p)
else:
    print "entered invalid character"
Dharmesh Fumakiya
  • 2,276
  • 2
  • 11
  • 17
  • #dharmesh sir its working.please suggest me good book for python i am beginner in python. i have done with c,c++,php,java. – Manjot Singh Sep 07 '17 at 17:31
  • @ManjotSingh you can learn basic concept from here, its very helpful for beginners: https://www.cs.uky.edu/~keen/115/Haltermanpythonbook.pdf – Dharmesh Fumakiya Sep 07 '17 at 18:15