first of all my apoligies if i asked something irrelevant, i am new to programming ad also new in python, my question is:
i have to write a simple program in which i have to ask for the number of employee in the company and then i have to create database of the entries, entry contains name of employee, hi/her salary and remarks.
i already write this program by putting number of employee fixed but when number of employee are not fixed then how to save each input in different variales, i think there is need to use loops but how to make this through loops?
nytman 0 Light Poster
Recommended Answers
Jump to PostHmm PEP-8 is gone fall in our head.
def __str__(self): return 'Name: '+self.name+', Salary: '+str(self.salary)+', Description: '+self.desc
And not to happy with all that +
def __str__(self): return 'Name: {} Salary: {} Description: {}'.format(self.name, self.salary, self.desc)
Jump to PostThe easiest to understand is to Use a function
def get_one_salary(ctr): while True: ##infinite loop salary=raw_input("enter the salary #%d: " % (ctr+1)) try: salary = float(salary) return salary except ValueError: print "could you please enter the correct salary? " n = int(raw_input("enter the number …
Jump to PostAs pyTony said, start your own thread if asking a different question.
Here's a quick and dirty iterpow function for positive exponents:def iterpow(b, e): r = 1 for i in range(e): r*=b return r
Jump to Post@nytman, as a beginner you could also use a list of tuples ...
# index constants for (name, salary, mark) tuple NAME = 0 SALARY = 1 MARK = 2 # create a list of (name, salary, mark) tuples mylist = [] while True: name = raw_input("Enter …
Jump to Postdef get_name(nme): while True: name = raw_input("enter the name #%s: " % (nme+1)) if name.isalpha(): return name print 'Use only letters!' print get_name(0)
All 23 Replies
TrustyTony 888 ex-Moderator Team Colleague Featured Poster
nytman 0 Light Poster
TrustyTony 888 ex-Moderator Team Colleague Featured Poster
nytman 0 Light Poster
TrustyTony 888 ex-Moderator Team Colleague Featured Poster
nytman 0 Light Poster
Lucaci Andrew 140 Za s|n
TrustyTony commented: No capitalized simple variables, please! -3
nytman 0 Light Poster
snippsat 661 Master Poster
woooee 814 Nearly a Posting Maven
Lennox 0 Newbie Poster
TrustyTony 888 ex-Moderator Team Colleague Featured Poster
Lucaci Andrew 140 Za s|n
Lennox 0 Newbie Poster
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague
nytman 0 Light Poster
nytman 0 Light Poster
TrustyTony 888 ex-Moderator Team Colleague Featured Poster
nytman 0 Light Poster
bumsfeld 413 Nearly a Posting Virtuoso
nytman 0 Light Poster
TrustyTony 888 ex-Moderator Team Colleague Featured Poster
nytman 0 Light Poster
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.