hi i need help to write two different functions

the first one is to displaysquareroots that asks the user for a number n, and displays the square roots of the number from 1 to n and to 3dp
so if the user enters 3 it displays

the square root of 1 is 1.000
the square root of 2 is 1.414
the square root of 3 is 1.732

the second one is to write a function peasinapod that asks the user for a number, and then draws that number of "peas" (green circles of radius 50) in a "pod" (graphics window of exactly the right size). E.g if the user enters 4, a graphics window of the size 400x100 should appear


and there is a third one write a numbered square function that has a parameter n and displays a "numbered" square of size n e.g a cqall numberedsquare(4) should result in


0 1 2 3
1 2 3 4
2 3 4 5
3 4 5 6

thank you

Editor's note:
moved to it's own thread

Recommended Answers

All 12 Replies

You forgot your code and error messages, don't forget to push (CODE) before pasting.

they are too long to add and they are wrong as it doesn't produce what I need

First and third problem at least are short problems, we want to know about you from the code you wrote, so we can help you best way.

for the first one i wrote
def drawdisplaySquareRoots():
n = input("Enter a number: ")
from math import sqrt
for n in range(1, n, 3):
root = sqrt(n)
print n

and the thrid one

def drawnumberedSquare(n):
#n = input("Enter a number wanted for the size of the square: ")
for i in range(1, n):
for j in range(1, n):
for k in range(1, n):

Not so far, actually, here is corrected first one, but you did forget to push that (CODE) button first!

def list_of_roots(): # function names are writen in small letters
    number = input("Enter a number: ")
    from math import sqrt
    for n in range(1, 1+number): # not every third, do not reuse n, not step of 3
        root = sqrt(n)
        print "the square root of %i is %.3f" % (n, root)

list_of_roots()

Third one partially corrected, show your own effort to make this work, hints should be enough to get you there:

def make_square(n):
    for i in range(1, n):
        for j in range(i, n):
##          for k in range(1, n): there is two dimensions in square
            print '%1i' % j,
        print

# it is better to get input out of action and pass the parameter              
n = input("Enter a number wanted for the size of the square: ")
make_square(n)

Actually almost nobody uses input statement in Python2, but instead use raw_input and convert the numbers themselves. Input has two much power, so if you know how you can call any functions to do damage to the computer system.

hi i have another problem which is to write a wall of eyes function that takes 3 parameters (radius,width and height) and displays, in a window of exactly the right size a wall of brown eyes of the given radius and dimensions e.g the function call wallofeyes(50, 4, 2) would give a 400x200 graphics window with 8 eyes using x's instead of eyes to look like

xxxx
xxxx

please help so far i have

def drawBrownEyeInCentre():
win = GraphWin()
centreOfWindow = Point(100,100)
drawCircle(win, Point(100,100), 60, "white")
drawCircle(win, Point(100,100), 30, "brown")
drawCircle(win, Point(100,100), 15, "black")

def drawwallOfEyes(radius, width, height):
win = GraphWin()
centreOfWindow = Point(100,100)
drawCircle(win, Point(100,100), 60, "white")
drawCircle(win, Point(100,100), 30, "brown")
drawCircle(win, Point(100,100), 15, "black")

You must loop for row and column and do right amount of step between them to produce not fixed values for center points.

i don't understand how to do that?

i don't understand how to do that?

Perhaps you should visit the tutor centre in Lion Gate building.
Remember, plagiarism can result in a zero mark for the unit, the whole year, or even exclusion. Make sure you learn from, but do not copy, any answers given here.

i know i haven't done any of that i ended up making my work frpm advice thank you for the help

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.