Hey, So I am a very experienced PHP programmer and completely new to python, I was wondering if someone could assist me with this program I am trying to make, The idea is simple The program has 10 different fortune quotes, the user needs to be able to tell the program how many quotes they want displayed, minimum however must be 5 quotes. I know I am new here to this DaniWeb but I have used this website for years for help with my PHP programming. Can someone please show what I would go about making a program such as this in Python? Any help is greatly appreciated.

I think an example would be easier than telling:

#!/usr/bin/env python
import random  # The random module is really handy.
quotes = ['quote 1', 'quote 2', 'quote 3','quote 4', 'quote 5', 'quote 6', 'quote 7', 'quote 8', 'quote 9', 'quote 10']

# Take the user's input, 
num_quotes = int(input('How many quotes? '))

if num_quotes < 5:
    print "You must choose more than four!"
    exit(2) # Kind of like die() in PHP

# Now the fancy stuff, we want to shuffle the array up:
random.shuffle(quotes)

# Now we want to choose the first n from the array and print them:
for j in range(0, num_quotes):
    print(quotes[j])

Notice that unlike PHP blocks of code are denoted by tabs (or four spaces), and lines don't end in a ;

Once I got used to it Python became my favorite programming language, because I can write almost exactly what comes out of my brain to code without too much conversion, it is almost like pseudo-code.

- Joe

commented: nice approach +15
commented: very well explained and a great help much appreciated. +0

Do you want to do this in the console, as the post above, or did you intend on using a GUI. Some sample input and output would also help.

I think an example would be easier than telling:

#!/usr/bin/env python
import random  # The random module is really handy.
quotes = ['quote 1', 'quote 2', 'quote 3','quote 4', 'quote 5', 'quote 6', 'quote 7', 'quote 8', 'quote 9', 'quote 10']

# Take the user's input, 
num_quotes = int(input('How many quotes? '))

if num_quotes < 5:
    print "You must choose more than four!"
    exit(2) # Kind of like die() in PHP

# Now the fancy stuff, we want to shuffle the array up:
random.shuffle(quotes)

# Now we want to choose the first n from the array and print them:
for j in range(0, num_quotes):
    print(quotes[j])

Notice that unlike PHP blocks of code are denoted by tabs (or four spaces), and lines don't end in a ;

Once I got used to it Python became my favorite programming language, because I can write almost exactly what comes out of my brain to code without too much conversion, it is almost like pseudo-code.

- Joe

Thank you so much! This helps me understand the language so much more. I really appreciate it Joe, thank you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.