struggling with these problems
1.Given that worst_offenders has been defined as a list with at least 6 elements, write a statement that defines lesser_offenders to be a new list that contains all the elements from index 5 of worst_offenders and beyond. Do not modify worst_offenders . I tried this but it didn't work: lesser_offenders = worst_offenders[5:6] 2.Given a variable temps that refers to a list, all of whose elements refer to values of type float , representing temperature data, compute the average temperature and assign it to a variable named avg_temp . Besides temps and avg_temp , you may use two other variables -- k and total . I'm not sure about this one but this is what I have: for k in range(len(temps)): total += temps[k] avg_temp = total / len(temps) 3.Associate the sum of the non-negative values in the list numbers with the variable sum . is it this: for numbers in sum: if sum +=? I'm confused at #3 the most i'm not doing it in python 3.2.3 it's called Myprogramminglab. -- http://mail.python.org/mailman/listinfo/python-list
Problem with importing in Python
I'm trying to import a python file it keeps saying: ImportError: cannot import name Circle Here is the file I'm trying to import: Circle.py import math class circle: #Construct a circle object def __init__(self, radius = 1): self.radius = radius def getPerimeter(self): return 2 * self.radius * math.pi def getArea(self): return self.radius * self.radius * math.pi def setRadius(self, radius): self.radius = radius from Circle import Circle def main(): #Create a circle with a radius 1 circle1 = Circle() print(The area of the circle of radius, circle1.radius, is , circle1.getArea()) #Create a circle with a radius 25 circle2 = Circle(25) print(The area of the circle of radius, circle2.radius, is , circle2.getArea()) #Create a circle with a radius 125 circle3 = Circle(125) print(The area of the circle of radius, circle3.radius, is , circle3.getArea()) #Modify circle radius circle2.radius = 100 # or Circle2.setRadius(100) print(The area of the circle of radius, circle2.radius, is , circle2.getArea()) main() # Call the main function How can I solve this problem? Thanks in advance. -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with importing in Python
On Friday, January 11, 2013 5:25:24 PM UTC-5, Adnan Sadzak wrote: Python is case sensitive. Circle and circle is not same. /* sent from android */ On Jan 11, 2013 11:22 PM, su29090 129...@gmail.com wrote: I'm trying to import a python file it keeps saying: ImportError: cannot import name Circle Here is the file I'm trying to import: Circle.py import math class circle: #Construct a circle object def __init__(self, radius = 1): self.radius = radius def getPerimeter(self): return 2 * self.radius * math.pi def getArea(self): return self.radius * self.radius * math.pi def setRadius(self, radius): self.radius = radius from Circle import Circle def main(): #Create a circle with a radius 1 circle1 = Circle() print(The area of the circle of radius, circle1.radius, is , circle1.getArea()) #Create a circle with a radius 25 circle2 = Circle(25) print(The area of the circle of radius, circle2.radius, is , circle2.getArea()) #Create a circle with a radius 125 circle3 = Circle(125) print(The area of the circle of radius, circle3.radius, is , circle3.getArea()) #Modify circle radius circle2.radius = 100 # or Circle2.setRadius(100) print(The area of the circle of radius, circle2.radius, is , circle2.getArea()) main() # Call the main function How can I solve this problem? Thanks in advance. -- http://mail.python.org/mailman/listinfo/python-list It still keeps showing the same message. -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with importing in Python
On Friday, January 11, 2013 5:27:21 PM UTC-5, Chris Angelico wrote: On Sat, Jan 12, 2013 at 9:17 AM, su29090 wrote: Circle.py class circle: from Circle import Circle Inside the Circle module is a class named circle. You can't import Circle from that. But Python isn't Java. You don't have to put each class into its own file. Just put class circle (or class Circle to follow Python naming convention) into the other file, whose name you haven't given. If they're already in the same file, then just drop the import. Easy! By the way: main() # Call the main function You'll need to put that flush left. At the moment, that call is part of the definition of main(). Hope that helps! ChrisA It worked! Thanks so much! :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with importing in Python
On Friday, January 11, 2013 5:43:10 PM UTC-5, Dave Angel wrote: On 01/11/2013 05:17 PM, su29090 wrote: I'm trying to import a python file it keeps saying: ImportError: cannot import name Circle Here is the file I'm trying to import: Circle.py import math class circle: #Construct a circle object def __init__(self, radius = 1): self.radius = radius def getPerimeter(self): return 2 * self.radius * math.pi def getArea(self): return self.radius * self.radius * math.pi def setRadius(self, radius): self.radius = radius from Circle import Circle def main(): #Create a circle with a radius 1 circle1 = Circle() print(The area of the circle of radius, circle1.radius, is , circle1.getArea()) #Create a circle with a radius 25 circle2 = Circle(25) print(The area of the circle of radius, circle2.radius, is , circle2.getArea()) #Create a circle with a radius 125 circle3 = Circle(125) print(The area of the circle of radius, circle3.radius, is , circle3.getArea()) #Modify circle radius circle2.radius = 100 # or Circle2.setRadius(100) print(The area of the circle of radius, circle2.radius, is , circle2.getArea()) main() # Call the main function How can I solve this problem? Thanks in advance. As Adnan has pointed out, Python is case insensitive. You're apparently trying to refer to the class Circle by the name circle, or the other way around. Some comments on asking clear questions: 1) Specify the Python version. I presume 3.3It probably doesn't matter here, but it might have. 2) When showing two source files, identify where each starts and ends, and what the second one is called. 3) When showing an error, include the entire traceback, not just the last line. Now, there are conventions to follow as well (see Pep8). One is that modules should use all lowercase, and classes should begin with a capital. So the source file of your module should be named circle.py and the class Circle. When you imported and instantiated the class, you assumed it was called Circle, but when you defined it, you mistakenly called it circle. The next error is the accidental indentation of the call to main(). As it stands now, it's a recursive call to itself. And main() will never be called, because there's no call at top-level. -- DaveA Thanks for explanation which was very clear! -- http://mail.python.org/mailman/listinfo/python-list
Problems on these two questions
I all of the other problems but I have issues with these: 1.Given a positive integer n , assign True to is_prime if n has no factors other than 1 and itself. (Remember, m is a factor of n if m divides n evenly.) 2.An arithmetic progression is a sequence of numbers in which the distance (or difference) between any two successive numbers if the same. This in the sequence 1, 3, 5, 7, ... , the distance is 2 while in the sequence 6, 12, 18, 24, ... , the distance is 6. Given the positive integer distance and the positive integer n , associate the variable sum with the sum of the elements of the arithmetic progression from 1 to n with distance distance . For example, if distance is 2 and n is 10 , then sum would be associated with 26 because 1+3+5+7+9 = 25 . Thanks in advance. -- http://mail.python.org/mailman/listinfo/python-list
Re: Problems on these two questions
On Sunday, November 18, 2012 8:52:35 PM UTC-5, su29090 wrote: I did all of the other problems but I have issues with these: 1.Given a positive integer n , assign True to is_prime if n has no factors other than 1 and itself. (Remember, m is a factor of n if m divides n evenly.) 2.An arithmetic progression is a sequence of numbers in which the distance (or difference) between any two successive numbers if the same. This in the sequence 1, 3, 5, 7, ... , the distance is 2 while in the sequence 6, 12, 18, 24, ... , the distance is 6. Given the positive integer distance and the positive integer n , associate the variable sum with the sum of the elements of the arithmetic progression from 1 to n with distance distance . For example, if distance is 2 and n is 10 , then sum would be associated with 26 because 1+3+5+7+9 = 25 . Thanks in advance. I'm using Python 3.2 -- http://mail.python.org/mailman/listinfo/python-list
Python questions help
I brought a python book and i'm a beginner and I read and tried to do the questions and I still get it wrong. How to create a program that reads an uspecified number of integers, that determines how many positive and negative values have been read, and computes the total and average of the input values(not counting zeroes). My program have to end with the input 0 and have to display the average as a floating-point number. Use nested loops that display the following patterns in separate programs: 1 12 123 1234 12345 123456 123456 12345 1234 123 12 1 1 21 321 4321 54321 654321 Write a program that computes the following summation: 1/ 1+square root of 2 + 1/ 1+square root of 2 + square root of 3 + 1/ 1+square root of 3 + square root of 4...+ 1/ 1+square root of 624 + square root of 625 How to a program to draw a chessboard using range? Thanks -- http://mail.python.org/mailman/listinfo/python-list