Python Forum
Calculator code issue using list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Calculator code issue using list
#1
The problem is that when I choose / and input 5 and 0 (2nd number as 0) it is giving 0.0 but not printing the divisior is zero


#!/usr/bin/python3
num=input("please select operator +,-,*,/ or q to quit")
while num != 'q':
   numlist=input("please enter at least 2 numbers ").split()
   numlist=[float(i) for i in numlist]
   total = numlist[0]
   del numlist[0]
   if num == '+':
      for i in numlist:
         total = i + total
      print (total)
   elif num == '-':
      for i in numlist:
         total = i - total
      print (total)
   elif num == '*':
      for i in numlist:
         total = i * total
      print (total)
   elif num =='/':
      if i in numlist ==0:
         print ("divisior is zero")
      else:
         for i in numlist:
            total = i / total
         print (total)
   num=input("please select operator +,-,*,/ or q to quit")
Reply


Messages In This Thread
Calculator code issue using list - by kirt6405 - Jun-11-2021, 09:46 PM
RE: Calculator code issue using list - by topfox - Jun-11-2021, 10:01 PM
RE: Calculator code issue using list - by kirt6405 - Jun-11-2021, 10:04 PM
RE: Calculator code issue using list - by Yoriz - Jun-11-2021, 10:10 PM
RE: Calculator code issue using list - by topfox - Jun-11-2021, 10:13 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  needing some help to write some code for a game calculator rymdaksel 2 1,802 Mar-08-2025, 03:02 AM
Last Post: bevisandrew
  List Comprehension Issue johnywhy 5 2,179 Jan-14-2024, 07:58 AM
Last Post: Pedroski55
  Updating Code And Having Issue With Keys Xileron 8 3,553 May-25-2023, 11:14 PM
Last Post: DigiGod
  Python List Issue Aggie64 5 3,045 Jun-30-2022, 09:15 PM
Last Post: Aggie64
  List to table issue robdineen 2 2,173 Nov-07-2021, 09:31 PM
Last Post: robdineen
  NameError issue with daughter's newb code MrGonk 2 2,270 Sep-16-2021, 01:29 PM
Last Post: BashBedlam
  Issue accessing data from Dictionary/List in the right format LuisSatch 2 3,119 Jul-25-2020, 06:12 AM
Last Post: LuisSatch
  For List Loop Issue Galdain 2 2,849 Dec-31-2019, 04:53 AM
Last Post: Galdain
  IndexError: List index out of range issue Adem 1 5,160 Nov-01-2019, 10:47 PM
Last Post: ichabod801
  Issue with code for auto checkout nqk28703 2 3,089 Nov-01-2019, 09:33 AM
Last Post: nqk28703

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020