Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with homework
#1
I am starting my journey in the world of programming (this after a class at the university), my knowledge of the subject is close to zero ... and this is taking me to get into tutorials to learn Python 3, I'm liking it, but i suck at this, so I request support from a charitable soul that can guide me with the following exercises, I am on the subject of functions using def, so we are asked to solve the exercises in that way. I'm a little desperate, because I feel that when I try to solve it I'm chopping stone with a piece of wood ... and yes it is my homework, but i losing my mind Wall :

Exercise 3. [25 marks] Write a program that asks the user for a numeric value and print the next output to the console function of said value, for this example the numerical value was 5:

12345
01234
00123
00012
00001

Exercise 4. [15/30 points] Write a program that asks the user for a numeric value and print the next output to the console depending on this value, for this example the numerical value was 5:

\2345
1\345
12\45
123\5
1234\

Exercise 5. [15/30 points] Write a program that receives a numerical value and prints the next hourglass figure in function of said numeric value, for this example the value was 9:

123456789
.1234567
..12345
...123
....1
...123
..12345
.1234567
123456789

Exercise 6. (50 points) Make a program that generates the following sequence of digits:

First, the user is asked for the number of rows to be calculated. The number of rows must be between 11 and 20 and the The result will appear in the console output as indicated in the figure. If the user enters a value less than 11 rows, adjust the value from rows to 11. If the user enters a value greater than 20, adjust the value of rows to 20.

..........1
.........232
........34543
.......4567654
......567898765
.....67890109876
....7890123210987
...890123454321098
..90123456765432109
.0123456789876543210
123456789010987654321

Exercise 7. [25 marks] Write a program that asks the user for a numeric value and prints the next output to the console function of said value, for this example the numerical value was 5:

##
#o#
#oo#
#ooo#
#oooo#

Exercise 8. [30 marks] Write a program that predicts the approximate size of a population of organisms. The application must request information from the initial number of organisms, the daily increase of the population (as a percentage) and the number of days that organisms will be allowed to multiply. For example, assume that the user enters the following values:

Initial number of organisms: 2
Initial Increase (in%): 30
Days of reproduction: 10

The program should print the following table:
Day Approximate Population
1 2
2 2.6
3 3.38
4 4,394
5 5.7122
6 7.42586
7 9.653619
8 12.5497
9 16.31462
10 21.209
Reply
#2
Ok, when you get stuck, post the specific part your stuck on with code in python code tags and any errors received in error tags.
Reply
#3
in exercise 3 this is haw far i got:

def conteo():
    n = 5
    acc = ""
    for i in range(n+1):
        acc += str(i)
        
        print(acc[1:n+1])

conteo()
Output:
1 12 123 1234 12345
i think that with this the others Will be arround the seme lines (i think...).
Reply
#4
exercise 3 example output is
Output:
12345 01234 00123 00012 00001
but yours is
Output:
1 12 123 1234 12345
Which is correct ?
Reply
#5
the first one, i don't know how to put it upside down and add the ceros
Reply
#6
(Mar-16-2019, 10:02 PM)charlykelley Wrote: the first one, i don't know how to put it upside down and add the ceros

Hint: always consult with documentation. Just write str. into you interactive session and press TAB twice and wonderful world of built in string methods will open up.

>>> str.
str.capitalize(    str.isalpha(       str.ljust(         str.rstrip(
str.casefold(      str.isascii(       str.lower(         str.split(
str.center(        str.isdecimal(     str.lstrip(        str.splitlines(
str.count(         str.isdigit(       str.maketrans(     str.startswith(
str.encode(        str.isidentifier(  str.mro(           str.strip(
str.endswith(      str.islower(       str.partition(     str.swapcase(
str.expandtabs(    str.isnumeric(     str.replace(       str.title(
str.find(          str.isprintable(   str.rfind(         str.translate(
str.format(        str.isspace(       str.rindex(        str.upper(
str.format_map(    str.istitle(       str.rjust(         str.zfill(
str.index(         str.isupper(       str.rpartition(    
str.isalnum(       str.join(          str.rsplit(
Methods names are usually very expressive, there is one with promising name: str.zfill(

>>> help(str.zfill)
zfill(self, width, /)
    Pad a numeric string with zeros on the left, to fill a field of the given width.
    
    The string is never truncated.
(END)
So what? Maybe something along those lines:

>>> spam = 'ham'
>>> spam.zfill(3)
ham
>>> spam.zfill(5)
00ham
>>> spam[:-1].zfill(5)
000ha
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#7
Thank you, i'll work with this to solve the exercises.

Thanks for the time invested in this.
Reply
#8
Do, i managed to solve the exercises but the last one, this how far i got:

def calculo_de_poblacion(numero):
    print("Day"+"   "+"Aproximate population")
    dia = 1
    population_growt = 1.3
    print("1" + "      " + "2")
    for i in range (numero):
        population = 2
        dia += 1
        population_growt += (population * 1.3)/2
        print(str(dia) +"      " + str(population_growt))

calculo_de_poblacion(10-1)
Output:
Day Aproximate population 1 2 2 2.6 3 3.9000000000000004 4 5.2 5 6.5 6 7.8 7 9.1 8 10.4 9 11.700000000000001 10 13.000000000000002
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020