473,657 Members | 2,432 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

raw_input passing to fun



the output of this code below is not what one would expect, it outputs
all kind of numbers and it never stops, I want to ask the user for a
number and then print out the multiplication table up to that number.

thanks

*************** *************** *************** *************** ****
import math

def printMultiples( n, hight):
i = 1
while i <= hight:
print n*i, '\t',
i = i + 1
print
def printMultTable( hight):
i = 1
while i <= hight:
printMultiples( i, i)
i = i + 1

num = raw_input ("produce a multiplication table up to: ")
printMultTable( num)
*************** *************** *************** *************** ****
Apr 28 '06 #1
2 1076
On 28/04/2006 2:04 PM, Gary Wessle wrote:

the output of this code below is not what one would expect, it outputs
all kind of numbers and it never stops, I want to ask the user for a
number and then print out the multiplication table up to that number.
That's what you want, but not what you did. You asked them for a string.

thanks

*************** *************** *************** *************** ****
import math
Not used.

def printMultiples( n, hight):
i = 1
while i <= hight:
print n*i, '\t',
i = i + 1
print
def printMultTable( hight):
i = 1
while i <= hight:
Temporarily, insert here:
print "types:", type(i), type(hight)
print "values:", i, hight
if i > 100: return
printMultiples( i, i)
i = i + 1

num = raw_input ("produce a multiplication table up to: ")
printMultTable( num)


Try this: printMultTable( int(num))

You may wish to consider changing "hight" to "height" :-)

Apr 28 '06 #2
John Machin <sj******@lexic on.net> writes:
On 28/04/2006 2:04 PM, Gary Wessle wrote:
the output of this code below is not what one would expect, it
outputs
all kind of numbers and it never stops, I want to ask the user for a
number and then print out the multiplication table up to that number.


That's what you want, but not what you did. You asked them for a string.
thanks
*************** *************** *************** *************** ****
import math


Not used.
def printMultiples( n, hight):
i = 1
while i <= hight:
print n*i, '\t',
i = i + 1
print
def printMultTable( hight):
i = 1
while i <= hight:


Temporarily, insert here:
print "types:", type(i), type(hight)
print "values:", i, hight
if i > 100: return
printMultiples( i, i)
i = i + 1
num = raw_input ("produce a multiplication table up to: ")
printMultTable( num)


Try this: printMultTable( int(num))

You may wish to consider changing "hight" to "height" :-)


thank you
Apr 28 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2514
by: Hugh | last post by:
I am using python 2.3 through the PythonWin program on windows. I would like to create a console-based interactive session. The program raw_input is almost exactly what I'd like, except that whenever I call raw_input(), it pops up a window on my screen. I'd much rather have it read from the interactive window. Is there something out there, as easy as raw_input(), that I can use? Thanks for any clues!
2
7233
by: J. W. McCall | last post by:
I'm working on a MUD server and I have a thread that gets keyboard input so that you can enter commands from the command line while it's in its main server loop. Everything works fine except that if a player enters the 'shutdown' command, everything shuts down, but the input thread is still sitting waiting for enter to be pressed for raw_input. After enter is pressed, it exits back to the command prompt as it should. I'm wondering if...
0
1816
by: dale | last post by:
Python newbie disclaimer on I am running an app with Tkinter screen in one thread and command-line input in another thread using raw_input(). First question - is this legal, should it run without issue? If not can you point me to a description of why. While updating objects on the screen I get a segfault after an indeterminate number of updates. It doesn't seem to matter how quickly the updates occur, but it does segfault faster...
1
2942
by: JerryKreps | last post by:
Hi, folks -- I'm a Python pup. As you can see from the session copied at the end of this post, I have the latest version of Python, and I've been using the Editor-Shell of the latest version of Boa Constructor while going through some Python tutorials. Everything was working as expected until I started using the raw_input built-in function. There seems to be some unreliable behavior in Boa Constructor's Editor - Shell. If you look...
21
8757
by: planetthoughtful | last post by:
Hi All, As always, my posts come with a 'Warning: Newbie lies ahead!' disclaimer... I'm wondering if it's possible, using raw_input(), to provide a 'default' value with the prompt? I would like to include the ability to edit an existing value (drawn from an SQLite table) using a DOS console Python app, but my gut
17
4183
by: Stuart McGraw | last post by:
In the announcement for Python-2.3 http://groups.google.com/group/comp.lang.python/msg/287e94d9fe25388d?hl=en it says "raw_input(): can now return Unicode objects". But I didn't see anything about this in Andrew Kuchling's "2.3 What's New", nor does the current python docs for raw_input() say anything about this. A test on a MS Windows system with a cp932 (japanese) default locale shows the object returned by raw_input() is a str()...
6
2257
by: oliver | last post by:
Hey Everyone, This is probably going to sound like a bit of a stupid question - but why does (in the following code) the script just continue to run past the raw_input, when the user hasn't entered anything? if __name__ == "__main__": bucket_name = raw_input('Name of the bucket you wish the files to be placed into? ') update_s3()
7
2037
by: Mike Kent | last post by:
It's often useful for debugging to print something to stderr, and to route the error output to a file using '2>filename' on the command line. However, when I try that with a python script, all prompt output from raw_input goes to stderr. Consider the following test program: === Start test.py === import sys
8
5301
by: Dox33 | last post by:
I ran into a very strange behaviour of raw_input(). I hope somebody can tell me how to fix this. (Or is this a problem in the python source?) I will explain the problem by using 3 examples. (Sorry, long email) The first two examples are behaving normal, the thirth is strange....... I wrote the following flabbergasting code: #-------------------------------------------------------------
0
8395
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8310
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8826
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4155
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4306
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1615
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.