LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 04-19-2015, 04:11 PM   #1
NuNu43
LQ Newbie
 
Registered: Aug 2014
Location: Florida
Distribution: Zorin, Puppy
Posts: 1

Rep: Reputation: Disabled
Python Question


Hello Giants,



I know almost nothing about python, I can make it print, or pick my lottery numbers.

I just found a great way to study for college class, I made a very simple program to run in the terminal.

It simply uses "print" and "raw_input"

It asks a question through raw_input, and compares the answer with
"if". If the answer is right, you get a good job, if not, it just goes to the next line.

I know how to do nothing else, but my ideas keep coming, and surpassing my programming ability.

One thing I have done, is print information between questions.u
But it just prints it in one big block and all at once.

How can I make the text appear slowly like it's typing,

You know, like the movies in the 90's......

Also, I would like to know how to make loops.
So it loops the question back to you until you get it right.....
 
Old 04-20-2015, 12:53 PM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,147

Rep: Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264Reputation: 1264
Try "Learn Python the Hard Way". Its for people who want to jump in and start programming rather than sit on their hands in a class.

http://learnpythonthehardway.org/book/
 
Old 04-20-2015, 01:03 PM   #3
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,236

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
Quote:
How can I make the text appear slowly like it's typing,

You know, like the movies in the 90's......
Code:
import time
import sys

for character in "I'm typing this\n":
	sys.stdout.write(character)
	sys.stdout.flush()
	time.sleep(0.25)

Last edited by dugan; 04-20-2015 at 01:04 PM.
 
2 members found this post helpful.
Old 04-20-2015, 01:30 PM   #4
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
@dugan: Nice and amazing code. Using 0.5 sec looks good.
 
Old 04-24-2015, 07:53 AM   #5
Samsonite2010
Member
 
Registered: Apr 2015
Distribution: Debian
Posts: 267
Blog Entries: 1

Rep: Reputation: 117Reputation: 117
Quote:
Originally Posted by dugan View Post
Code:
import time
import sys

for character in "I'm typing this\n":
	sys.stdout.write(character)
	sys.stdout.flush()
	time.sleep(0.25)
Well done sir - Python is simply awesome!
 
1 members found this post helpful.
Old 04-26-2015, 10:02 PM   #6
Fabio Paolini
Member
 
Registered: Dec 2008
Location: Brazil
Distribution: Slackware 12 Debian 5
Posts: 52

Rep: Reputation: 17
Here is a very simple example with a loop

Code:
count = 0
while True:
    if count:
        print 'Try again: '
    else:
        print 'Put your name:'
    a =  raw_input()
    print 'You have tried %s' % a
    if a == 'myName':
        print 'right'
        break
    else:
        print 'wrong'
    count += 1
    
print 'Leaving ...'
 
  


Reply



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
A question about python yimaizhe Linux - Newbie 6 06-20-2011 08:43 AM
Python question gamehack Programming 5 01-03-2005 05:21 AM
Python question bluefire Programming 5 09-28-2004 12:30 PM
python question ywchen2000 Programming 1 04-20-2004 11:46 PM
Python question m4rccd Programming 1 08-24-2003 06:04 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:19 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration