- Strength to Increase Rep
- +0
- Strength to Decrease Rep
- -0
- Upvotes Received
- 11
- Posts with Upvotes
- 8
- Upvoting Members
- 9
- Downvotes Received
- 2
- Posts with Downvotes
- 2
- Downvoting Members
- 1
34 Posted Topics
Re: This is clearly a homework question. Maybe pay more attention in class? We would be more than willing to help you with a specific issue, but coming here and asking people to do it for you seems a bit lazy don't you think? | |
Re: Another way to do it using if statments: [code] >>> def grades(): grade = int(raw_input("Enter the student's grade: ")) if grade >= 90: return 'A' if grade >= 80: return 'B' if grade >= 70: return 'C' if grade >= 60: return 'D' return 'F' >>> grades() Enter the student's … | |
I am currently trying to load a few script through boost python. I ran into some trouble today while trying to launch idle from it however and I cannot figure out the cause of the issue. This is on a windows 2008 machine, and I am currently running Python 3.3 … | |
Re: Welcome to the forums! For the future, please use the code tags around your script to make it easier to read :) ([url]http://www.daniweb.com/forums/announcement114-3.html[/url]) This does look like a homework question, so please read the rules about posting homework questions here: [url]http://www.daniweb.com/forums/announcement114-2.html[/url] Here is an example for comming up with prime … | |
[code] class MyList(list): def __new__(cls, *p, **k): if not '_the_instance' in cls.__dict__: cls._the_instance = list.__new__(cls) return cls._the_instance def append(self, name): if name not in self: list.append(self, name) def extend(self, names): for name in names: if name in self: continue list.append(self, name) def remove(self, name): if name in self: list.remove(self, name) … | |
Re: does this give u a hint? [code] >>> pattern ('w1', '', 'w3', '', 'w5') >>> line 'w1 A w3 B w5 w6 w7 w8' >>> for index in range(len(pattern)): if pattern[index] in ['', line.split(' ')[index]]: print line.split(' ')[index] w1 A w3 B w5 >>> [/code] | |
Re: I do believe that is in fact a school book. It was written to be teached in a class setting. You may be able to find a instructor's edition (with the anwsers to all the excersises, tests, ect...) If you have some scripts that are not working or questions... You … | |
Re: Does this help? [code] >>> f = \ ''' System Configuration: blah blah blah blah blah blah System Configuration: blah blah blah blah blah blah System Memory Configuration: blah blah blah blah blah blah System Processor Configuration: blah blah blah blah blah blah System Adapter Configuration: blah blah blah blah … | |
Re: [QUOTE=mms6;1029045]I want to allow certain characters to a string For example I want strA to contain either 'A' or 'B' or 'C' or 'D' How do I do that, help would be greatly appreciated. Thanks strA = 'A' or 'B' or 'C' or 'D'[/QUOTE] Your questions are soooo vague. Could … | |
Re: Whats lens()? Is that supposed to be len() ? Here is one of several possible solutions to your problem: [code] >>> def ispair(strA, strB): # Is strA too long or short? if len(strA) != 1: return False # Is strB too long or short? if len(strB) != 1: return False … | |
Re: im actually not sure why that happens, nor have i ever had a situation where i needed them to stay in order.. [code]al x = {'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5} >>> x {'four': 4, 'three': 3, 'five': 5, 'two': 2, 'one': 1} [/code] dicts sort … | |
Re: [QUOTE=mms6;1027932] I get output "ou" What happened to the rest "ouuo"? please, someone I need some assistance [/QUOTE] What was your input? | |
Re: why not use a set for this? [code] info = {'x1': 123, 'y1': 456, 'x2: 789, 'y2': 012} [/code] | |
Re: [QUOTE=vnproduktionz;1027910]wow that help a bit so now i got this [code] for line in budgetLineList: if "Total Current" in line: word=line.split() good=word[3] float(''.join(good)) if "State" in line: word1=line.split() good1=word1[4] float(''.join(good1)) print float(''.join(good1))/float(''.join(good))*100 [/code] now my probelm is that when it prints it only prints the last value it doesnt go … | |
Re: [QUOTE=vnproduktionz;1028267][CODE]reply=float(raw_input("Enter your choice: ")) if reply!=1 or reply!=2: print "Not a Valid Choice" [/CODE] i cant use while loops other wise i prob wouldve done so. Basically im trying to get the user input to only allow the numbers 1 or 2. anything else should give a not a valid … | |
Re: I am trying to figure out a situation which requires looping... [code] >>> string 'Take out all the 111111111111111111' >>> string.replace('1','').strip() 'Take out all the' [/code] See what i mean? If you just need a while example... [code] >>> x = 0 >>> while x < 10: x += 1 … | |
Re: Does this give you any insight? [code] >>> class employee(object): def __init__(self): self.name = raw_input('Enter employee name: ') >>> class calc(employee): def pr(self): print self.name >>> d = calc() Enter employee name: Bob >>> d.pr() Bob [/code] | |
Re: [code] >>> mystring = 'I have a t on my keyboard' >>> mystring.replace(' ', ' \') 'I \\have \\a \\t \\on \\my \\keyboard' [/code] | |
Re: try: [code] print('The temperature is %f degrees Fahrenheit.' % fahenheit) [/code] | |
Re: Could you reword your question a little better? maybe give an example of what your looking for, and any code your have allready tried and failed with? | |
Re: Here is a quick example of a class and some attributes: You can see A and B are unique entities, but use a common class. [code] # A class class example(object): attribute1 = 1 attribute2 = 2 def example_method(self): return 'method function' A = example() B = example() # Some … | |
Re: You mean something like this? [code] def numtolet(num): letters = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'] return letters[num] [/code] >>> numtolet(1) 'B' >>> numtolet(14) 'O' | |
Re: [code] >>> L1 [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]] >>> L2 [1, 2, 3, 4, 11] >>> L3 = [] >>> for x in L1: for y in L2: if y in x and x not in L3: L3.append(x) >>> L3 [[1, 2, 3], … | |
How would i do this? [code] import random name = random random.name [/code] I dont cant to use name = random.random, as name is something that could change | |
Re: Isnt this allready a method of string? [code] >>> x = 'Testing ONE TWO THREE' >>> x.swapcase() 'tESTING one two three' >>> [/code] | |
Re: might be able to do something like.. [code] # Correct answers answers = { 'songA': {'title': 'hello', 'composer': 'bob', 'year': 1984}, 'songB': {'title': 'goodbye', 'composer': 'jan', 'year': 1983}, 'songC': {'title': 'i love pie', 'composer': 'carl', 'year': 1982} } # Holder for user's anwsers values = {} # Ask questions for … | |
Re: does this help you? [code] >>> n = 10 >>> for i in range(1,(n + 1)): if n % i == 0: print '%i factors into %i' % (i, n) 1 factors into 10 2 factors into 10 5 factors into 10 10 factors into 10 >>> [/code] | |
Could anyone lend some help? Trying to figure out how to do this in SQLite3 (this is mySQL) [code] CREATE TABLE car_contacts ( id INTEGER NOT NULL AUTO_INCREMENT, carriers_id CHAR NOT NULL, name CHAR NULL, phone CHAR NULL, phone_ext INTEGER NULL, fax CHAR NULL, email CHAR NULL, PRIMARY KEY(id, carriers_id), … | |
lets say i have 2 lists: lista = [1,2,3,5,6,7] listb = [4,5,6,7,8,9,10] The lists can be different lengths, and may not allways be unequal lengths. The higher average will allways be in listb, so that is the 1 constant we can rely on. This works for even teams: [code] average … | |
Re: [QUOTE=MichelleCrews;1001890]hey, ima first time programmer and i no clue whats going on someone please help!! i have to write a function called number_of_2s that includes one parameter, N, where N is a positive integer that is no more than 10 digits long. the function should return the number of times … | |
lets say i have a list: L = [1,2,3,4,5,6,7,8,9] x could be anything, but it wont ever be longer than len(L) - 1.. just for what im asking, im setting it to 3 x = 3 value could also be anything, but not exceeding sum(L) value = 8 What i … | |
![]() | Re: you could use zip... [code] >>> users = ('bob', 'carl', 'edna') >>> passwords = ('1234', 'pass', 'icu812') >>> zip(users, passwords) [('bob', '1234'), ('carl', 'pass'), ('edna', 'icu812')] >>> mydict = dict(zip(users, passwords)) >>> mydict['bob'] '1234' >>> dict(zip(users, passwords))['bob'] '1234' [/code] or you could use indexes: [code] >>> passwords[users.index('bob')] '1234' [/code] u … ![]() |
Re: Maybe this will help you see what you have done wrong: [code] >>> myvar = 0 >>> while myvar != 8: myvar = int(input("input 8 to stop the loop: ")) input 8 to stop the loop: 4 input 8 to stop the loop: 23949 input 8 to stop the loop: … | |
Re: [QUOTE=Lamb_Chops;999902]I can't for the life of me solve this problem :icon_confused: Write a function called rand_goodbye(name) that returns (not prints!) a string that says goodbye, where the goodbye phrase is chosen at random from these three possibilities: * Goodbye name * See ya' later name * name: stay cool! I'm … |