| Computer Science Canada Quick question from a super noob. | 
| Author: | SIXAXIS [ Thu Feb 21, 2008 3:28 pm ] | 
| Post subject: | Quick question from a super noob. | 
| Hi, As you can see, I'm extremely new to Python, and although it's not the first language that I'm learning to program in, I don't know how to do anything. My question is: How do you make a variable a real number instead of an integer? | |
| Author: | Nick [ Thu Feb 21, 2008 3:31 pm ] | 
| Post subject: | RE:Quick question from a super noob. | 
| instead of assigning 10 to the variable foo let's call it, try assigning 10.0 | |
| Author: | McKenzie [ Thu Feb 21, 2008 7:07 pm ] | ||||||
| Post subject: | Re: Quick question from a super noob. | ||||||
| Right, unless your problem is something like: 
 in which case you need to use float if you want a decimal answer, like: 
 Keep in mind that Python is dynamically typed so: 
 works just fine. | |||||||
| Author: | Sniper4Life [ Sun Apr 12, 2009 10:40 pm ] | 
| Post subject: | RE:Quick question from a super noob. | 
| mckenzie...how would u set it so that the decimals can only go SO FAR...like you can only have 4 or 3 decimals...or only 1...?????? | |
| Author: | [Gandalf] [ Mon Apr 13, 2009 1:13 am ] | ||
| Post subject: | RE:Quick question from a super noob. | ||
| Well, I'm not McKenzie, however... 
 | |||
| Author: | Sniper4Life [ Mon Apr 13, 2009 9:55 am ] | ||
| Post subject: | RE:Quick question from a super noob. | ||
| so....%2f should do it? oh ya i tried your thing and it works ty but u cant use it if you do firstpx-secondpx as what your gonna round 
 k ive been stuck on this code like forever cus i dont know how to round it....at the last line when you print distance...how can u make it so you can round it? since its printing an operation...i dont kno...how to round it...O.O | |||
| Author: | Sniper4Life [ Mon Apr 13, 2009 10:53 am ] | ||
| Post subject: | RE:Quick question from a super noob. | ||
| nvr mind i just figured it out its very simple ^^ i nvr learned bout floats in python so it was a bit confusing for me... 
 ya that solves my problem ^^ (ps-awesome im not a noob programmer any more  ) | |||
| Author: | Zeroth [ Mon Apr 13, 2009 11:06 am ] | ||||
| Post subject: | Re: Quick question from a super noob. | ||||
| Be very, very, very careful with using input. Its basically evaluating all input typed by the user. So one could feasibly use straight python code, write a function, or manipulate the program state via input. Your usage of input means that the user could input either an int or a float. You need to use float(firstpx) to force them to floats. Second of all, its much nicer to use: 
 The use of the brackets around the two arguments creates a tuple, which python automatically unpacks to the positional arguments in the string. You can also do some really cool stuff like this: 
 What happened there is that the key is inside the ()'s, and the format is right after, the s. By passing a dict, you can fill in the string as necessary, so long as empty keys still have a value(ideally, just a blank string ""). Of course, any class that behaves like a dict will work here too  . | |||||
| Author: | wtd [ Mon Apr 13, 2009 11:10 am ] | 
| Post subject: | Re: RE:Quick question from a super noob. | 
| Sniper4Life @ Mon Apr 13, 2009 11:40 am wrote: mckenzie...how would u set it so that the decimals can only go SO FAR...like you can only have 4 or 3 decimals...or only 1...?????? Keep in mind that you can't control the accuracy of the information stored as a floating point number. You can only control the accuracy of the output. | |
| Author: | Sniper4Life [ Mon Apr 13, 2009 11:27 am ] | 
| Post subject: | RE:Quick question from a super noob. | 
| ya wtd thats what i meant for question introEx5 on mckenzie's exercises i need to control the output... | |