View the Most Wanted LQ Wiki articles.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 12-16-2004, 12:55 AM   #1
Registered: Oct 2003
Distribution: Ubuntu 7.04
Posts: 889
Blog Entries: 1

Rep: Reputation: 30
Some questions on integrating a couple simple python programs.

Ok, im taking this tutorial that was found on I love it. Its fun to read, and its easy. On a certain chapter, (I forget which) it gives a little assignment to integrate a question program with a number program. Heres the two.

#keeps asking for numbers until count have been entered.
#Prints the average value.

sum = 0.0

print "This program will take several numbers than average them"
count = input("How many numbers would you like to sum:")
current_count = 0

while current_count < count:
current_count = current_count + 1
print "Number ",current_count
number = input("Enter a number:")
sum = sum + number

print "The average was:",sum/count

The question program...

# Waits until a password has been entered. Use control-C to break out with out
# the password

#Note that this must not be the password so that the
# while loop runs at least once.
password = "foobar"

#note that != means not equal
while password != "unicorn":
password = raw_input("Password:")
print "Welcome in"

Sample run:

Passwordpen sesame
Welcome in
I would just like to know how would I integrate these 2 together, so I could get how many times I tried to get the password, and if I did over 3 times, how would I say something line "that was hard wasn't it?" This is what I thought, but this is not my full, messy program, since its confusing to hell anyways. Do I put somewhere in these 2 programs this...?

n = input("Number? ")
if n < 0:
print "The absolute value of",n,"is",-n
print "The absolute value of",n,"is",n

Thought obviously I think I would change the ineger to the "count" shown in program one, and I would take out the input, so the user doesn't add a number before they are told how many times it took them to find out the password.

Thanx in advance! Oya, im a when it comes to programing. Plz don't flame me to death.
Old 12-17-2004, 01:32 PM   #2
Registered: Dec 2004
Location: Atlanta, GA U.S.
Distribution: I play with them all :-)
Posts: 316

Rep: Reputation: 30
Make both of them to be functions. Put them into a single app and Bob's your uncle.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Couple of simple usability questions... dangerousdave Linux - Newbie 2 08-21-2005 07:56 PM
Apache, MySQL, PHP, a couple simple questions. The_Messiah Linux - Software 3 04-09-2005 06:17 PM
Integrating programs (RAR, Firebird etc. NeilM Linux - Newbie 0 04-05-2004 06:00 PM
Installing Programs - A simple question from my simple mind jmp875 Linux - Newbie 6 02-18-2004 10:03 PM
A couple of simple questions Redeye2 Mandriva 3 02-11-2004 12:50 AM

All times are GMT -5. The time now is 04:54 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration