Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    10
    Rep Power
    0

    Newbie here..and im desperate..


    I was given this algorithm to do in python and I cant even get thru the first part...Im getting a syntax error for the equal sign im using.

    I need to write an algorithm that, given an input integer N, prints the following pattern. The first line of the pattern has N stars. The next line has N-1 stars, the next has N-2 stars and so ontill there is only one star to be printed. You may print a star using the command "print". You may print a new line character using command "print NEWLINE". What is the time compexity of this algorithm in Big O notation?
    Heres an example pattern for N=5
    *****
    ****
    ***
    **
    *

    Any help will be greatly appreciated


    also, can someone point me in the right direction on this program...

    I need to write a program that calculates the total amount of a meal purchased at a restaurant. The program should ask the user to enter the charge for the food, and then calculate the amount of 20% tip, and 8.75 % tax.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2005
    Location
    U.S A.Z.
    Posts
    24
    Rep Power
    0
    You might get more help if you post what code you have.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    10
    Rep Power
    0
    Originally Posted by knutrainer
    You might get more help if you post what code you have.
    it was pseudo code, and then i wass asked to implement it in python
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2005
    Location
    U.S A.Z.
    Posts
    24
    Rep Power
    0
    You said you were getting a syntax error?
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    10
    Rep Power
    0
    Originally Posted by knutrainer
    You said you were getting a syntax error?
    yes.

    for i = N to 1

    the equal sign is returning an error
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2005
    Location
    U.S A.Z.
    Posts
    24
    Rep Power
    0
    for i = N to 1? This isn't even close to correct. I think you need to do your own home work but here I have tried to at least set you on the right path. I put ? marks in so I didnt complete your assignment for you.

    Code:
    n = raw_input('Enter number: ')
    n = ???(n)
    while n ?? 0:
    	print n ? '*'
    	n ?? 1
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    10
    Rep Power
    0
    Originally Posted by knutrainer
    for i = N to 1? This isn't even close to correct. I think you need to do your own home work but here I have tried to at least set you on the right path. I put ? marks in so I didnt complete your assignment for you.

    Code:
    n = raw_input('Enter number: ')
    n = ???(n)
    while n ?? 0:
    	print n ? '*'
    	n ?? 1
    n = ???(n)

    Im stumped here. Everything else is ok..
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2005
    Location
    U.S A.Z.
    Posts
    24
    Rep Power
    0
    If you use raw_input to get a number you have to convert that input to an integer. Variables stored using raw_input are string values. If you try subtract by one from the variable N you would get an error.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    10
    Rep Power
    0
    Originally Posted by knutrainer
    If you use raw_input to get a number you have to convert that input to an integer. Variables stored using raw_input are string values. If you try subtract by one from the variable N you would get an error.
    wow, you just confused me. I was inputting the number after the parenthesis...
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    10
    Rep Power
    0
    i cant get it to work. Thanks though.
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2005
    Location
    U.S A.Z.
    Posts
    24
    Rep Power
    0
    Ok try to remove the n = ???(n) and see what happens when you run the code.
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    10
    Rep Power
    0
    Originally Posted by knutrainer
    Ok try to remove the n = ???(n) and see what happens when you run the code.
    Nothing. I give up.
  24. #13
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2005
    Location
    U.S A.Z.
    Posts
    24
    Rep Power
    0
    You get an error. Right? Well you should because n needs to be converted to an integer. How do you convert an str value to an int value?
  26. #14
  27. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    10
    Rep Power
    0
    Originally Posted by knutrainer
    for i = N to 1? This isn't even close to correct. I think you need to do your own home work but here I have tried to at least set you on the right path. I put ? marks in so I didnt complete your assignment for you.

    Code:
    n = raw_input('Enter number: ')
    n = ???(n)
    while n ?? 0:
    	print n ? '*'
    	n ?? 1
    n = raw_input('Enter number: ')

    Do i type this in python as it is exactly with spaces and all?
    or do input my own number?
  28. #15
  29. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2005
    Location
    U.S A.Z.
    Posts
    24
    Rep Power
    0
    Enter it into python as is. When you do it will then ask you to enter a number. Pick any number you want.
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo