473,386 Members | 1,708 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

My main does not call any modules / functions

I am getting frustrated here. I thought if it doesn't run I will atleast get some error. Hoever, the program does not do anything when I run it. Any suggestions?

Expand|Select|Wrap|Line Numbers
  1. def getInput():
  2.     speedLimit = int (raw_input ("Enter the speed limit: "))
  3.     clockedSpeed = int (raw_input ("Enter the clocked speed of the car: "))
  4.  
  5. def calculation():
  6.     overSpeed = clockedSpeed - speedLimit
  7.     fine = 50.00 + (5.00 * overSpeed)
  8.     if overSpeed:
  9.         if clockedSpeed > 90:
  10.             toalfine = fine + 200.00
  11.         elif clockedSpeed <= 90:
  12.             totalFine = fine
  13.     else:
  14.         fine = 0.00
  15.         totalFine = 0.00
  16.     tooFast = clockedSpeed - 90
  17.  
  18. def printOut():
  19.     print "Posted speed limit: \n\n"+speedLimit
  20.     print "Clocked speed : \n\n"+clockedSpeed
  21.     if clockSpeed > speedLimit:
  22.         print "\n * Driver was speeding."
  23.         print "\n * Driver was speeding by " + overSpeed + "mph"
  24.         if clockedSpeed >90:
  25.             print "\n * Driver was speeding by " + overSpeed + "mph & exeeding 90 mph"
  26.         elif clockedSpeed <= speedLimit:
  27.             print "\n * Driver was not speeding.\n"
  28.             print "\n * Driver was speeding by " + clockedSpeed + "mph"
  29.  
  30. def speedingFine():
  31.     print "Speeding fine: "
  32.     print "Penalty for over 90 mph: "+tooFast
  33.     print "Total fine: "+totalFine
  34.  
  35. #Main--------------------------------------------
  36.     getinput()
  37.     calculate()
  38.     printOut()
  39.     speedingFine()
  40.  
Dec 5 '06 #1
6 1359
bvdet
2,851 Expert Mod 2GB
Use a forward slash instead of a backslash in your code tags. You can check how your post will display by hitting the 'Preview Post' button.
Dec 5 '06 #2
bvdet
2,851 Expert Mod 2GB
Python is 'case' and 'spelling' sensitive. getinput() will not call getInput() and calculate() will not call calculation(). Slow down and check your code. I test all my code in an IDE (usually Pythonwin) incrementally to spot coding errors. I strongly suggest that you call functions with arguments and return values similar to this:
Expand|Select|Wrap|Line Numbers
  1. ## Function definition - returns a float rounded down to the previous
  2. ## 'increment'
  3. import math
  4.  
  5. def round_length_last(length, increment="1/16"):
  6.     if not increment:
  7.         return length
  8.     else:
  9.         return float(math.floor(length/increment) * increment)
  10.  
  11. a = round_length_last(120.4567, increment=0.5)
  12. print "%0.4f" % (a)
Dec 5 '06 #3
will do so. Thanks a lot bvdet I supposed since I am new to programming I need to learn a lot.
Dec 6 '06 #4
Python is indent sensitive, too. The part of your code that is calling the functions looks like it is indented. That means that it is still part of the function that is above it.
Dec 7 '06 #5
bartonc
6,596 Expert 4TB
Python is indent sensitive, too. The part of your code that is calling the functions looks like it is indented. That means that it is still part of the function that is above it.
Thanks for the post Subsciber123.
Dec 7 '06 #6
bartonc
6,596 Expert 4TB
Python is indent sensitive, too. The part of your code that is calling the functions looks like it is indented. That means that it is still part of the function that is above it.
What he means is:

Expand|Select|Wrap|Line Numbers
  1. def getInput():
  2.     speedLimit = int (raw_input ("Enter the speed limit: "))
  3.     clockedSpeed = int (raw_input ("Enter the clocked speed of the car: "))
  4.  
  5. def calculation():
  6.     overSpeed = clockedSpeed - speedLimit
  7.     fine = 50.00 + (5.00 * overSpeed)
  8.     if overSpeed:
  9.         if clockedSpeed > 90:
  10.             toalfine = fine + 200.00
  11.         elif clockedSpeed <= 90:
  12.             totalFine = fine
  13.     else:
  14.         fine = 0.00
  15.         totalFine = 0.00
  16.     tooFast = clockedSpeed - 90
  17.  
  18. def printOut():
  19.     print "Posted speed limit: \n\n"+speedLimit
  20.     print "Clocked speed : \n\n"+clockedSpeed
  21.     if clockSpeed > speedLimit:
  22.         print "\n * Driver was speeding."
  23.         print "\n * Driver was speeding by " + overSpeed + "mph"
  24.         if clockedSpeed >90:
  25.             print "\n * Driver was speeding by " + overSpeed + "mph & exeeding 90 mph"
  26.         elif clockedSpeed <= speedLimit:
  27.             print "\n * Driver was not speeding.\n"
  28.             print "\n * Driver was speeding by " + clockedSpeed + "mph"
  29.  
  30. def speedingFine():
  31.     print "Speeding fine: "
  32.     print "Penalty for over 90 mph: "+tooFast
  33.     print "Total fine: "+totalFine
  34.  
  35. #Main--------------------------------------------
  36. getinput()
  37. calculate()
  38. printOut()
  39. speedingFine()
Has correct indetation.
Dec 18 '06 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Rhamphoryncus | last post by:
First a bit about myself. I've been programming in python several years now, and I've got several more years before that with C. I've got a lot of interest in the more theoretical stuff (language...
45
by: Steven T. Hatton | last post by:
This is a purely *hypothetical* question. That means, it's /pretend/, CP. ;-) If you were forced at gunpoint to put all your code in classes, rather than in namespace scope (obviously classes...
27
by: poiuz24 | last post by:
aeh, this may be stupid, but could s.b. please explain to me why the following won't link (gcc 3.3)? foo.cpp = """ namespace foo { int main () { return 0; }
1
by: terrencel | last post by:
I was told to look at some old C code that was ported to C++. One of the file is like: ========================================= CPPClass* someCPPVar = NULL; extern "C" {
1
by: Andy | last post by:
Hi! I have a main application here and developed 2 modules as DLL files, which will be updated from time to time. The main application ships without the modules so i want to be able, to put the...
16
by: Geoff Jones | last post by:
Hi What is the closest equivalent to Main in a VB.Net form? Geoff
11
by: Jim | last post by:
Hi, I have created an import module. And would like to access a function from the main script, e.g., file abc.py: ################### def a(): m() return None
3
by: GIJosh | last post by:
Hi guys. I'm new to python, so go easy. Heres my problem. I've got my main file, Python Paint.py #Python Paint.py from graphics import * import time import functions win =...
17
by: mike-yue | last post by:
and, Is it possible to call one main function from another main function? Thanks guys.
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.