LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 12-15-2004, 11:55 PM   #1
RHLinuxGUY
Member
 
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 pythong.org. 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.

average2.py

#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...

Password.py

# 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:

Password:auo
Password:y22
Passwordassword
Passwordpen sesame
Password:unicorn
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
else:
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, 12:32 PM   #2
Harlin
Member
 
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.
 
  


Reply


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 06:56 PM
Apache, MySQL, PHP, a couple simple questions. The_Messiah Linux - Software 3 04-09-2005 05:17 PM
Integrating programs (RAR, Firebird etc. NeilM Linux - Newbie 0 04-05-2004 05:00 PM
Installing Programs - A simple question from my simple mind jmp875 Linux - Newbie 6 02-18-2004 09:03 PM
A couple of simple questions Redeye2 Mandriva 3 02-10-2004 11:50 PM


All times are GMT -5. The time now is 05:28 AM.

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