Hello there DANIWEB!

Now I know that there are already many different discussions asking for python ideas for beginners, but I thought maybe this could be a discussion for all different abilities. For example, if I wanted to reply with a Beginner idea, I would type:

BEGINNER

And the same for INTERMEDIATE and EXPERT.
That way, if anybody of those three levels tries to look for something, all they have to do is ctrl+f and type in beginner, intermediate, or expert!

Many thanks!
Jet

BEGINNER
Hey again, I thought to start this discussion off, I could post an idea of my own. I did a simple calculator, copied from a book. Thought it might help some people to start.

name=raw_input("What is your name?")
print"Welcome to the program,",name
again=1
while again==1:
    first=int(raw_input("Type the first number:\n> "))
    second=int(raw_input("Type the second number:\n> "))

    print first,"added to",second,"equals",first+second
    print first,"minus",second,"equals",first-second
    print(first,"multiplied by",second,"equals",first*second

    again=int(raw_input("Type 1 to enter more numbers, or any other    number to quit:\n> ")

I hope this is alright for you all. You can add in division, or extra addition, multiplication, subtraction, or division by reversing the variables 'second' and 'first' in the print statements.

Open for feedback...
Many thanks!
Jet

INTERMEDIATE
Hi,
maybe you could add some functionality to the program by giving the user the option of which maths you want the program to complete.

name=raw_input("What is your name?")
        print"Welcome to the program,",name
        again=1
        while again==1:
            Choice=int(raw_input("Press 1 for addition 2 for subtraction or 3 for multiplication"))
            first=int(raw_input("Type the first number:\n> "))
            second=int(raw_input("Type the second number:\n> "))
            if Choice == 1:
                 print first,"added to",second,"equals",first+second
            elif Choice == 2:
                 print first,"minus",second,"equals",first-second
            elif Choice == 3:
                 print first,"multiplied by",second,"equals",first*second
            again=int(raw_input("Type 1 to enter more numbers, or any other number to quit:\n> ")

Thanks for reading!
Lemon

commented: Well done! Very good idea. Many thanks! +0
''' filename_list_given_dir1.py
use module glob to list all the filenames of .jpg files
or any extension(s) you specify in a given directory
'''

import glob
import os

# all files (split off file names) in a given directory
directory = "C:/Temp/*.jpg"
# this would give you all files
#directory = "C:/Temp/*.*"
for path in glob.glob(directory):
    #print(path)  # test
    # separate path from filename
    dirname, filename = os.path.split(path)
    print(filename)

Challenge, how would you show all .py and .txt files in a given directory?

commented: Is this the right place to be posting this? +0

@ZZucker Perhaps you shouldn't have posted this here.... Wrong topic?

Beginner
Hey there. Just an idea based on one from another discussion.

import random
#imports random library

a=random.randint(1,11)
b=random.randint(1,11)
c=random.randint(1,11)

if a==1:
   text1="An adjective and a noun e.g A happy camel"
elif a==2:
   text1="An adjective and a noun"
elif a==3:
   text1="An adjective and a noun"
elif a==4:
   text1="An adjective and a noun"
elif a==5:
   text1="An adjective and a noun"
elif a==6:
   text1="An adjective and a noun"
elif a==7:
   text1="An adjective and a noun"
elif a==8:
   text1="An adjective and a noun"
elif a==9:
   text1="An adjective and a noun"
elif a==10:
   text1="An adjective and a noun"
elif a==11:
   text1="An adjective and a noun"

if b==1:
   text2="a verb and adverb e.g brutally murders"
elif b==2:
   text2="a verb and adverb"
elif b==3:
   text2="a verb and adverb"
elif b==4:
   text2="a verb and adverb"
elif b==5:
   text2="a verb and adverb"
elif b==6:
   text2="a verb and adverb"
elif b==7:
   text2="a verb and adverb"
elif b==8:
   text2="a verb and adverb"
elif b==9:
   text2="a verb and adverb"
elif b==10:
   text2="a verb and adverb"
elif b==11:
   text2="a verb and adverb"

if c==1:
   text3="a noun. (adjectives can be added) e.g it's mother's photo."
if c==2:
   text3="a noun.
if c==3:
   text3="a noun.
if c==4:
   text3="a noun.
if c==5:
   text3="a noun.
if c==6:
   text3="a noun.
if c==7:
   text3="a noun.
if c==8:
   text3="a noun.
if c==9:
   text3="a noun.
if c==10:
   text3="a noun.
if c==11:

print(text1,text2,text3)
   text3="a noun.

Replace where appropriate, doesn't have to be 11, can be any number.

Many thanks!
Jet

This is the first dadaist thread here. Your code does not make sense. Do something useful instead !

Beginner
Edit for the above

import random
#imports random library
a=random.randint(1,11)
b=random.randint(1,11)
c=random.randint(1,11)
if a==1:
   text1="An adjective and a noun e.g A happy camel"
elif a==2:
   text1="An adjective and a noun"
elif a==3:
   text1="An adjective and a noun"
elif a==4:
   text1="An adjective and a noun"
elif a==5:
   text1="An adjective and a noun"
elif a==6:
   text1="An adjective and a noun"
elif a==7:
   text1="An adjective and a noun"
elif a==8:
   text1="An adjective and a noun"
elif a==9:
   text1="An adjective and a noun"
elif a==10:
   text1="An adjective and a noun"
elif a==11:
   text1="An adjective and a noun"
if b==1:
   text2="a verb and adverb e.g brutally murders"
elif b==2:
   text2="a verb and adverb"
elif b==3:
   text2="a verb and adverb"
elif b==4:
   text2="a verb and adverb"
elif b==5:
   text2="a verb and adverb"
elif b==6:
   text2="a verb and adverb"
elif b==7:
   text2="a verb and adverb"
elif b==8:
   text2="a verb and adverb"
elif b==9:
   text2="a verb and adverb"
elif b==10:
   text2="a verb and adverb"
elif b==11:
   text2="a verb and adverb"
if c==1:
   text3="a noun. (adjectives can be added) e.g it's mother's photo."
if c==2:
   text3="a noun."
if c==3:
   text3="a noun."
if c==4:
   text3="a noun."
if c==5:
   text3="a noun."
if c==6:
   text3="a noun."
if c==7:
   text3="a noun."
if c==8:
   text3="a noun."
if c==9:
   text3="a noun."
if c==10:
   text3="a noun."
if c==11:
print(text1,text2,text3)

Many thanks!
Jet

@Gribouillis What do you mean? Be more specific otherwise I can't improve... :/

Learn, listen, logic.

@ZZucker What?! You're going to have to speak straight.

One that's currently linked in my signature.

Beginner-Intermediate

Consider the following two graphs: Click Here
The graph on the left is said to be two-colourable (or bipartite), because you are able to colour the nodes with two colours such that no adjacent nodes are the same colour.
It is impossible to colour the graph on the right with two colours such that no adjacent nodes share the same colour. Thus, it is not two-colourable.

Out of all possible graphs with 7 nodes, how many are two-colourable?

Expert

PyEditor1.0

from Tkinter import*
import tkDialog as tk_Dialog
from Stringl0 import Stringl0
import os
recents = []

class PyEditor:
    def doNew(self):
        self.text.delete(0.0,END)

    def doUndo(self):
        self.text.edit_undo()

    def doSaveAs(self):
        file = tk_FileDialog.asksavefile(mode='w')
        textoutput = self.text.get(0.0,END)
        file.write(textoutput.rstrip())
        file.write('\n')

    def doOpen(self):
        file = tk_FileDialog(mode='r')
        fileContets = file.read()
        recents.append(file)

        self.text.delete(0.0,END)
        self.text.insert(0.0,fileContents)

    def doRun(self):
        file = tk_FileDialog.askopenfile(mode='r')
        os.system('c:\\Python25\\python ' + file.name)

    def __init__(self):
        self.root = Tk()
        self.root.title('PyEditor1.0')
        self.root.minsize(with=800,height=535)

        menubar = Menu(self.root)

        filemenu = Menu(menubar,tearoff=0)
        filemenu.add_command(label='New File',command=self.doNew,accelerator='Ctrl+N)

        file.add_command(label='Open',command=self.doOpen,accelerator='CtrlO')

        filemenu.add_command(label='Save As',command=self.doSaveAs,accelerator='Ctrl+Shift+S')

        filemenu.add_command(label='Run Program',command=self.doRun,accelerator='Ctrl+R')

        editmenu = Menu(editmenu,tearoff=0)
        editmenu.add_command(label='Undo',command=self.doUndo,accelerator='Ctrl+Z')

        menubar.add_cascade(label='File',menu=filemenu)
        self.root.config(menu=menubar)
        editmenu.add_cascade(label='Edit',menu=editmenu)
        self.root.config(menu=editmenu)

        self.text = Text(self.root,undo=True)
        self.text.pack(expand=YES,fill=BOTH)

if __name__ == '__main__':
    app = PyEditor()
    app.root.mainloop()
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.