Python code problems i am making a code for class where i need to ask the user 7 questions and get a total sum of carbon

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Python code problems i am making a code for class where i need to ask the user 7 questions and get a total sum of carbon

Post by answerhappygod »

Python code problems
i am making a code for class where i need to ask the user 7
questions and get a total sum of carbon the individual person uses
per year. I was given a dataframe, and told explicitly that i need
to call the dataframe in the code (ie i cant input directly the
numbers then sum them). everything works fine individually and
returns the correct numbers, but when i sum them up, i run into
issues, specifically for questions 6 and 7 of my list of questions.
When one is commented out, the other works perfectly, and vice
versa, but when they both are being run, the program returns one of
the values as 0, instead of the value it should be returning. (see
pictures of output below) How do i fix this
Python Code Problems I Am Making A Code For Class Where I Need To Ask The User 7 Questions And Get A Total Sum Of Carbon 1
Python Code Problems I Am Making A Code For Class Where I Need To Ask The User 7 Questions And Get A Total Sum Of Carbon 1 (4.6 KiB) Viewed 61 times
Python Code Problems I Am Making A Code For Class Where I Need To Ask The User 7 Questions And Get A Total Sum Of Carbon 2
Python Code Problems I Am Making A Code For Class Where I Need To Ask The User 7 Questions And Get A Total Sum Of Carbon 2 (44.42 KiB) Viewed 61 times
Python Code Problems I Am Making A Code For Class Where I Need To Ask The User 7 Questions And Get A Total Sum Of Carbon 3
Python Code Problems I Am Making A Code For Class Where I Need To Ask The User 7 Questions And Get A Total Sum Of Carbon 3 (11.51 KiB) Viewed 61 times
import numpy as np # mathematical import matplotlib.pyplot as plt import pandas as pd

= #6.) ask the user if they have pets print("Do You have any pets ?\n1) No\n2) Yes- 1\n3) Yes-2 vall = int(input("Enter value: ")) info = df.loc(cat.str.contains("Pets", case=False)] idx=df.index [cat=='Pets'] if vall = 1: pet=0. total = pd. Series( [0.3) elif vall == 2: pet-1. total+= m_p.iloc[idx] *freq. iloc(idx] elif vali == 3: pet=2. total += m_p.iloc(idx] *freq. iloc(idx] elif vall == 4: pet=3. total += m_p.iloc[idx] *freq.iloc(idx] else: print('error) total_6= total.sum()*pet print(total_6) #6.) how often do you buy clothes- monthly then add 25% to print("How often do you buy clothes? \n1) monthly \n2) year vali = int(input("Enter value: ")) info = df.loc(cat.str.contains ("Clothing", case=False)] idx=df.index [cat='Clothing 'l if vali =1: total+= m_p.iloc (idx] *freq.iloc(idx] clothes= 12. elif vali ==2: total += m_p.iloc(idx] *freq.iloc(idx) clothes = 1. elif val1==3 : total += m_p.iloc(idx] *freq.iloc idx] clothes = 6. else: print('error') total_7 = total.sum()*clothes print(total_7) total = total_6 + total_7 print (total)

Do You have any pets ? 1) No 2) Yes-1 3) Yes-2 4) Yes-3 Enter value: 2 1080.0 How often do you buy clothes? 1) monthly 2) yearly 3) bi-yearly Enter value: 2 0.0 1080.0
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply