Mike "Wuzzy121". Rest in peace, brother

Go Back   Tacoma World Forums > Off-Topic > Technology

Notices

Programming in Python

Reply
 
Thread Tools Search this Thread
Old 04-04-2013, 01:17 PM   #1
isu2014 [OP] isu2014 is online now
RAT Products
isu2014 is one of the sharper tools in the shedisu2014 is one of the sharper tools in the shedisu2014 is one of the sharper tools in the shedisu2014 is one of the sharper tools in the shedisu2014 is one of the sharper tools in the shedisu2014 is one of the sharper tools in the shedisu2014 is one of the sharper tools in the shedisu2014 is one of the sharper tools in the shedisu2014 is one of the sharper tools in the shedisu2014 is one of the sharper tools in the shedisu2014 is one of the sharper tools in the shed
 
isu2014's Avatar
Name: Ryan
Joined: Apr 2010, #35140
Location: Ames, IA
Age: 23
Gender: Dude
Posts: 10,651
isu2014's Tacoma Gallery
Programming in Python

I'm writing a program for class and I am struggling. Python is the programming software we use. The task:

User inputs-
enter the number of mouse traps (ie. 60 is our test number)
are you an iowa resident? (y/n)

Outputs-
Subtotal (ie. 115)
Tax (ie. 0 if iowa resident is answered n, 6.9 if iowa resident is answered y)
Total (ie. 115 or 121.9, depending on tax)

My code so far is attached. When I run the code, I get a sytax error at the colon after if res == y:
I'm not sure what to do to make this work. I've tried everything I know.
Attached Thumbnails
Programming in Python-screen-shot-2013-04-04-3.15.44-pm.png  
  Reply With Quote
Old 04-04-2013, 01:19 PM   #2
AKA Crash Bandicoot
ChamYota is one of the sharper tools in the shedChamYota is one of the sharper tools in the shedChamYota is one of the sharper tools in the shedChamYota is one of the sharper tools in the shedChamYota is one of the sharper tools in the shedChamYota is one of the sharper tools in the shedChamYota is one of the sharper tools in the shedChamYota is one of the sharper tools in the shedChamYota is one of the sharper tools in the shedChamYota is one of the sharper tools in the shedChamYota is one of the sharper tools in the shed
 
ChamYota's Avatar
Army: National Guard: Infantry/ROTC Cadet
Name: Cam
Joined: Jul 2011, #59431
Location: Clemson,South Carolina
Age: 20
Gender: Male
Posts: 8,001
ChamYota's Tacoma Gallery
I did python my first semester in college.

Is raw_input("") a valid input reading code? i've never seen that.
  Reply With Quote
Old 04-04-2013, 01:23 PM   #3
isu2014 [OP] isu2014 is online now
RAT Products
isu2014 is one of the sharper tools in the shedisu2014 is one of the sharper tools in the shedisu2014 is one of the sharper tools in the shedisu2014 is one of the sharper tools in the shedisu2014 is one of the sharper tools in the shedisu2014 is one of the sharper tools in the shedisu2014 is one of the sharper tools in the shedisu2014 is one of the sharper tools in the shedisu2014 is one of the sharper tools in the shedisu2014 is one of the sharper tools in the shedisu2014 is one of the sharper tools in the shed
 
isu2014's Avatar
Name: Ryan
Joined: Apr 2010, #35140
Location: Ames, IA
Age: 23
Gender: Dude
Posts: 10,651
isu2014's Tacoma Gallery
raw_input is used when the input is a string and input is for integers.
  Reply With Quote
Old 04-04-2013, 01:31 PM   #4
Member
Shaowei is on a distinguished road
Name: Ryan
Joined: Feb 2010, #30483
Location: New Mexico
Gender: Male
Posts: 68
Shaowei's Tacoma Gallery
Try this:

if res == 'y':
blah blah blah
else:
blah blah blah

The variable 'res' is a string. You need to compare it to a string. Without the quotes around y, Python considers it a variable and not a string. Hope this helps!
  Reply With Quote
Old 04-04-2013, 01:39 PM   #5
isu2014 [OP] isu2014 is online now
RAT Products
isu2014 is one of the sharper tools in the shedisu2014 is one of the sharper tools in the shedisu2014 is one of the sharper tools in the shedisu2014 is one of the sharper tools in the shedisu2014 is one of the sharper tools in the shedisu2014 is one of the sharper tools in the shedisu2014 is one of the sharper tools in the shedisu2014 is one of the sharper tools in the shedisu2014 is one of the sharper tools in the shedisu2014 is one of the sharper tools in the shedisu2014 is one of the sharper tools in the shed
 
isu2014's Avatar
Name: Ryan
Joined: Apr 2010, #35140
Location: Ames, IA
Age: 23
Gender: Dude
Posts: 10,651
isu2014's Tacoma Gallery
Quote:
Originally Posted by Shaowei View Post
Try this:

if res == 'y':
blah blah blah
else:
blah blah blah

The variable 'res' is a string. You need to compare it to a string. Without the quotes around y, Python considers it a variable and not a string. Hope this helps!
Tried it and I get the same syntax error. I'm gonna leave it like this though, since you are probably correct.
  Reply With Quote
Old 04-04-2013, 01:43 PM   #6
Member
Shaowei is on a distinguished road
Name: Ryan
Joined: Feb 2010, #30483
Location: New Mexico
Gender: Male
Posts: 68
Shaowei's Tacoma Gallery
Upon further inspection, the raw_input line in your attached image is missing a closing parentheses. I changed mine to match yours and I get the same error. Make sure you have closed off your parentheses in raw_input.
  Reply With Quote
Old 04-04-2013, 01:44 PM   #7
cheese'd out of my mind
Tuckerhump is one of the sharper tools in the shedTuckerhump is one of the sharper tools in the shedTuckerhump is one of the sharper tools in the shedTuckerhump is one of the sharper tools in the shedTuckerhump is one of the sharper tools in the shedTuckerhump is one of the sharper tools in the shedTuckerhump is one of the sharper tools in the shedTuckerhump is one of the sharper tools in the shedTuckerhump is one of the sharper tools in the shedTuckerhump is one of the sharper tools in the shedTuckerhump is one of the sharper tools in the shed
 
Tuckerhump's Avatar
Joined: May 2012, #79561
Location: CO / ND
Age: 25
Gender: Male
Posts: 841
Tuckerhump's Tacoma Gallery
Quote:
Originally Posted by Shaowei View Post
Upon further inspection, the raw_input line in your attached image is missing a closing parentheses. I changed mine to match yours and I get the same error. Make sure you having closed off your parentheses in raw_input.
x2, thats what i was thinking the error could be coming from
  Reply With Quote
Old 04-04-2013, 01:50 PM   #8
isu2014 [OP] isu2014 is online now
RAT Products
isu2014 is one of the sharper tools in the shedisu2014 is one of the sharper tools in the shedisu2014 is one of the sharper tools in the shedisu2014 is one of the sharper tools in the shedisu2014 is one of the sharper tools in the shedisu2014 is one of the sharper tools in the shedisu2014 is one of the sharper tools in the shedisu2014 is one of the sharper tools in the shedisu2014 is one of the sharper tools in the shedisu2014 is one of the sharper tools in the shedisu2014 is one of the sharper tools in the shed
 
isu2014's Avatar
Name: Ryan
Joined: Apr 2010, #35140
Location: Ames, IA
Age: 23
Gender: Dude
Posts: 10,651
isu2014's Tacoma Gallery
Quote:
Originally Posted by Shaowei View Post
Upon further inspection, the raw_input line in your attached image is missing a closing parentheses. I changed mine to match yours and I get the same error. Make sure you have closed off your parentheses in raw_input.
You are correct sir! Can't believe I missed that! Thank you much.
  Reply With Quote
Old 04-05-2013, 05:33 PM   #9
Senior Member
wileyC is one of the sharper tools in the shedwileyC is one of the sharper tools in the shedwileyC is one of the sharper tools in the shedwileyC is one of the sharper tools in the shedwileyC is one of the sharper tools in the shedwileyC is one of the sharper tools in the shedwileyC is one of the sharper tools in the shedwileyC is one of the sharper tools in the shedwileyC is one of the sharper tools in the shedwileyC is one of the sharper tools in the shedwileyC is one of the sharper tools in the shed
 
wileyC's Avatar
Joined: Oct 2011, #65685
Location: Centerville, OH
Gender: Male
Posts: 2,797
wileyC's Tacoma Gallery
...also, you can add a slight bit of robustness/improvement when dealing w/ string comparisons...

for example:

instead of;

if res == "y":

use;

if res.strip() == "y":

the strip method will remove any leading and trailing whitespace from strings...

also, you may want to ensure that the "case" doesn't matter;

if res.lower() == "y":

  Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help! Python 574 Reference Guide Cruzs2013SR5 2nd Gen. Tacomas 3 04-03-2013 04:33 AM
03 Tacoma Python Alarm Carito 1st Gen. Tacomas 4 06-19-2011 03:50 PM
Python Alarm Install Questions bfogelma Technical Chat 0 06-18-2011 12:02 PM
Python 1401 Remote Start bellassaiw10 1st Gen. Tacomas 0 06-13-2011 07:26 PM
Python Remote Start For sale ffblaze911 Buy / Sell / Trade 5 07-06-2010 03:21 PM


Copyright © 2014 Tacoma Forum. Tacoma World is not owned by, or affiliated with Toyota Motor Corporation.