Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,148,537 members, 7,801,507 topics. Date: Thursday, 18 April 2024 at 04:13 PM

Learning Programming. (my Nairaland Journal) - Programming (3) - Nairaland

Nairaland Forum / Science/Technology / Programming / Learning Programming. (my Nairaland Journal) (25376 Views)

Some Months Into Programming, My Excruciating Experience. / Avoid The Hard Ways Of Learning Programming / Help I"m Loosing Intrest Fast In Learning Programming. (2) (3) (4)

(1) (2) (3) (4) (5) (6) (7) (8) (9) (Reply) (Go Down)

Re: Learning Programming. (my Nairaland Journal) by naijasensei: 6:39pm On Nov 12, 2020
syluck:


Hello bro, sorry to disturb.

Please I need a better understanding of question number (9). I've tried so hard to understand what's it all about but I just keep getting a blank idea.

Then, number (11) and (14)

Proposed solution to Q9:

1 Like

Re: Learning Programming. (my Nairaland Journal) by syluck(m): 5:23am On Nov 15, 2020
naijasensei:


Question 9 is about a sequence referred to as the fibonacci sequence. It begins with two numbers: 1, 1. Subsequent numbers in the sequence are gotten by adding the two previous numbers together. For example, the third number is: 1 + 1 = 2. The fourth number is: 1 + 2 = 3. The fifth number is 2 + 3 = 5, and so on. Your program should request for the user to input the number of fibonacci numbers they want. E.g. inputting 3 should produce 1,1,2 while inputting 5 should produce 1,1,2,3,5.
One way of solving this problem is by using a loop. You will loop as many times as the user requests for, but for the first and second pass through the loop you will print(1).

Question 11 is about patterns, there are two major string patterns - the one with 19 asterisks and the one with 2 asterisks separated by 17 spaces. From the diagram, the default width is 19 asterisks while the default height is 4 asterisks. If a user requests for a box that is 40 asterisks wide by 6 asterisks high, you would use a for loop to print the asterisks 40 times in 6 passes - a nested for loop.
E.g.
for i in range(1, height+1):
for j in range(1, width+1):

Let me see what you will come up with.




Thanks for this input. I won't lie, it took me a while before understanding this angry
Re: Learning Programming. (my Nairaland Journal) by naijasensei: 5:32am On Nov 15, 2020
syluck:

Thanks for this input. I won't lie, it took me a while before understanding this angry

No shame in that. Some of the concepts are a bit abstract, so it might take a while to understand. Whenever you get stuck, just take your time, relax, do something else, then return to the problem.

1 Like

Re: Learning Programming. (my Nairaland Journal) by syluck(m): 8:21am On Nov 15, 2020
naijasensei:


No shame in that. Some of the concepts are a bit abstract, so it might take a while to understand. Whenever you get stuck, just take your time, relax, do something else, then return to the problem.
Okay.
Re: Learning Programming. (my Nairaland Journal) by Iconstar: 11:28am On Nov 15, 2020
syluck:


Greetings too.

I started learning Programming using python programming language. There are many others but if you like python, then u should begin with it. Below is the link to a thread of python video tutorials. It's quite concised and easily understandable.

https://www.nairaland.com/4945611/thread-tutorial-python-programming

Re: Learning Programming. (my Nairaland Journal) by syluck(m): 8:00pm On Nov 20, 2020
Came across this and I tried running the code.

Number 2 and 3 precisely. I'm having problem on both.

In Number 2, I ran the code according to the best of my knowledge but the only issue is having both the Fahrenheit and celcius on both (uppercase, lowercase, first letters both capital and small)

Then for number 3, I just need to understand how to implement the -273.15 when coding.

Thanks

Re: Learning Programming. (my Nairaland Journal) by naijasensei: 9:33am On Nov 21, 2020
syluck:
Came across this and I tried running the code.

Number 2 and 3 precisely. I'm having problem on both.

In Number 2, I ran the code according to the best of my knowledge but the only issue is having both the Fahrenheit and celcius on both (uppercase, lowercase, first letters both capital and small)

Then for number 3, I just need to understand how to implement the -273.15 when coding.

Thanks

Why are you using the eval function in your code?
Re: Learning Programming. (my Nairaland Journal) by syluck(m): 9:55am On Nov 21, 2020
naijasensei:


Why are you using the eval function in your code?
According to the pdf I'm using to work on, it has eval throughout. I kinda decided to use it though
Re: Learning Programming. (my Nairaland Journal) by syluck(m): 9:58am On Nov 21, 2020
I'm just glad I'm improving day by day grin

Re: Learning Programming. (my Nairaland Journal) by naijasensei: 10:04am On Nov 21, 2020
syluck:

According to the pdf I'm using to work on, it has eval throughout. I kinda decided to use it though

Drop it, you don't need it.
Try the following for Q2

Re: Learning Programming. (my Nairaland Journal) by naijasensei: 10:15am On Nov 21, 2020
syluck:
Came across this and I tried running the code.

Number 2 and 3 precisely. I'm having problem on both.

In Number 2, I ran the code according to the best of my knowledge but the only issue is having both the Fahrenheit and celcius on both (uppercase, lowercase, first letters both capital and small)

Then for number 3, I just need to understand how to implement the -273.15 when coding.

Thanks

For question 3, you are to use if...elif...else blocks
If you have a variable, temp, pointing to where the temperature in °C is stored. Then:

Point of note, I am only showing this to give you an idea. In practice, in a program, be careful when comparing floating point (decimal) numbers. Floating point arithmetic is not as straightforward as integer arithmetic.

Re: Learning Programming. (my Nairaland Journal) by syluck(m): 10:27am On Nov 21, 2020
naijasensei:


For question 3, you are to use if...elif...else blocks
If you have a variable, temp, pointing to where the temperature in °C is stored. Then:

Point of note, I am only showing this to give you an idea. In practice, in a program, be careful when comparing floating point (decimal) numbers. Floating point arithmetic is not as straightforward as integer arithmetic.
Does this automate the 273.15 to -273.15?
Cos that's really my problem. How to run the code inserting the -(minus) operator
Re: Learning Programming. (my Nairaland Journal) by naijasensei: 10:38am On Nov 21, 2020
syluck:

Does this automate the 273.15 to -273.15?
Cos that's really my problem. How to run the code inserting the -(minus) operator

My bad, put the negative sign (-) before the number -273.15. (-) is both a unary and binary operator.

1 Like

Re: Learning Programming. (my Nairaland Journal) by Vecto(m): 4:14pm On Nov 21, 2020
naijasensei:


For question 3, you are to use if...elif...else blocks
If you have a variable, temp, pointing to where the temperature in °C is stored. Then:

Point of note, I am only showing this to give you an idea. In practice, in a program, be careful when comparing floating point (decimal) numbers. Floating point arithmetic is not as straightforward as integer arithmetic.

Sorry do you code on mobile?
Re: Learning Programming. (my Nairaland Journal) by Vecto(m): 4:16pm On Nov 21, 2020
syluck:
I'm just glad I'm improving day by day grin
Well done bro. Coding on mobile can be quite stressful, eh?
What pdf are you using btw?
Re: Learning Programming. (my Nairaland Journal) by syluck(m): 5:09pm On Nov 21, 2020
Vecto:
Well done bro. Coding on mobile can be quite stressful, eh?

What pdf are you using btw?

Thanks bro.

Here is the pdf name

1 Like

Re: Learning Programming. (my Nairaland Journal) by syluck(m): 5:13pm On Nov 21, 2020
Vecto:


Sorry do you code on mobile?

Yes, most times. Can't be carrying my pc all the times
Re: Learning Programming. (my Nairaland Journal) by Vecto(m): 5:23pm On Nov 21, 2020
syluck:

Thanks bro.
Here is the pdf name
Thanks.

1 Like

Re: Learning Programming. (my Nairaland Journal) by naijasensei: 6:41pm On Nov 21, 2020
Vecto:


Sorry do you code on mobile?

No, I don't. I just used my mobile to illustrate some stuff. I code on my laptop.
Re: Learning Programming. (my Nairaland Journal) by naijasensei: 6:42pm On Nov 21, 2020
syluck:


Thanks bro.

Here is the pdf name

Say what? You're using a 2012 material?

2 Likes

Re: Learning Programming. (my Nairaland Journal) by syluck(m): 9:41pm On Nov 21, 2020
naijasensei:


Say what? You're using a 2012 material?
grin angry grin

Suggest a better one for me please
Re: Learning Programming. (my Nairaland Journal) by naijasensei: 8:43am On Nov 22, 2020
syluck:
grin angry grin

Suggest a better one for me please

Think like a computer scientist.
Automate the boring stuff with Python.

Make sure you get the latest editions. Even the one you are using, I suspect there might be a newer version.

5 Likes

Re: Learning Programming. (my Nairaland Journal) by syluck(m): 2:53pm On Nov 26, 2020
naijasensei:


Think like a computer scientist.
Automate the boring stuff with Python.

Make sure you get the latest editions. Even the one you are using, I suspect there might be a newer version.
Bro, on god sometimes the simplest algorithms are the hardest to code angry

Please can you help me out on number 10 and 12

Re: Learning Programming. (my Nairaland Journal) by Semtu(m): 3:57pm On Nov 26, 2020
syluck:

Bro, on god sometimes the simplest algorithms are the hardest to code angry

Please can you help me out on number 10 and 12

I'll give you hints for number 10, you learn better my figuring things out yourself. You'll need to collect 10 inputs from the user by calling input() through a loop. Outside the loop, create an empty list then append each input to the list while the loop is still valid. Once you've collected the inputs to a list, you can easily play with the python list by calling sorted(). This will sort the list elements in ascending order. Meaning that indexing the first element of the list would be the lowest since the values are sorted while the last would be the highest. To find the average, you can sum the list then divide by the len. Apply similar logic to the rest.

For the second part, this is one way to work through it.
import random
score = [ ]
number=random.randint(1,11)
trials=5
while trials>0:
```indent```guess=int(input('guess the number between 1 to 10: ')
```indent```if guess==number:
```indent``````indent```score.append(10)
```indent```else:
```indent``````indent```score.append(-1)
```indent```trials-=1

print(sum(score))

3 Likes

Re: Learning Programming. (my Nairaland Journal) by naijasensei: 5:34pm On Nov 26, 2020
Semtu:


I'll give you hints for number 10, you learn better my figuring things out yourself. You'll need to collect 10 inputs from the user by calling input() through a loop. Outside the loop, create an empty list then append each input to the list while the loop is still valid. Once you've collected the inputs to a list, you can easily play with the python list by calling sorted(). This will sort the list elements in ascending order. Meaning that indexing the first element of the list would be the lowest since the values are sorted while the last would be the highest. To find the average, you can sum the list then divide by the len. Apply similar logic to the rest.

For the second part, this is one way to work through it.
import random
score = [ ]
number=random.randint(1,11)
trials=5
while trials>0:
```indent```guess=int(input('guess the number between 1 to 10: ')
```indent```if guess==number:
```indent``````indent```score.append(10)
```indent```else:
```indent``````indent```score.append(-1)
```indent```trials-=1

print(sum(score))

Nice, great work.

For Q12 though, I believe score shouldn't be a list, rather it should be of type int. So:

score = 0
number = random.randint(1,10)
#different from random.randrange(1,11)

Because of this:
score.append(10) should be score += 10
score.append(-1) should be score -= 1

Thanks.

1 Like

Re: Learning Programming. (my Nairaland Journal) by syluck(m): 9:52pm On Nov 27, 2020
Semtu:


I'll give you hints for number 10, you learn better my figuring things out yourself. You'll need to collect 10 inputs from the user by calling input() through a loop. Outside the loop, create an empty list then append each input to the list while the loop is still valid. Once you've collected the inputs to a list, you can easily play with the python list by calling sorted(). This will sort the list elements in ascending order. Meaning that indexing the first element of the list would be the lowest since the values are sorted while the last would be the highest. To find the average, you can sum the list then divide by the len. Apply similar logic to the rest.

For the second part, this is one way to work through it.
import random
score = [ ]
number=random.randint(1,11)
trials=5
while trials>0:
```indent```guess=int(input('guess the number between 1 to 10: ')
```indent```if guess==number:
```indent``````indent```score.append(10)
```indent```else:
```indent``````indent```score.append(-1)
```indent```trials-=1

print(sum(score))

Thanks bro....my head be so heavy this days cos of running codes....
Re: Learning Programming. (my Nairaland Journal) by syluck(m): 5:41pm On Nov 28, 2020
naijasensei:


Nice, great work.

For Q12 though, I believe score shouldn't be a list, rather it should be of type int. So:

score = 0
number = random.randint(1,10)
#different from random.randrange(1,11)

Because of this:
score.append(10) should be score += 10
score.append(-1) should be score -= 1

Thanks.

Bro, there's this python concepts I really need to understand how it works....
I'll list then below:

1: for i in range (2, prompt+1):

Here, I know "prompt" could be a variable where a value is assigned to.....then, (2) is where we want the loop to start from.... My difficulty is understanding what +1 after the prompt stands for....
Like the example above I listed is used when running a code for "divisors of a number*...

2: for i range(1, num+1):
Indent""""""""factorial = factorial * i

Here, the +1 appears again.... But this time around it's the "factorial * i".... Pls I need to understand this concept really good.....

Lastly:

3: for i in range(1, prompt+1):
Indent"""""""""if(prompt %i ==0)
Indent"""""""""s += i

Here, I understand what prompt is, %i is, ==0 is, and s is... The problem is, "+=". I still don't understand vividly what's that all about...in short, u can explain the whole concept "s += i" to me please....

PS: i know that
+ is an addition operator
* Is a multiplication operator
= a equal sign operator ( mostly used to assign values to variables and vice versa)
Re: Learning Programming. (my Nairaland Journal) by syluck(m): 5:42pm On Nov 28, 2020
Hey, please anyone can help out...

Bovage
Semtu
Karleb

Thanks
Re: Learning Programming. (my Nairaland Journal) by Karleb(m): 6:18pm On Nov 28, 2020
Let say x has an initial value of 2.

When you do x += 2 it a short hand for x = x + 2, which will give you 4.

That means

x = x + 2 'and' x += 2 are thesame thing.

You can substitute the addition sign for any other arithmetic sign in python.

x = 4

x *= 4 #16

x //= 2 #8

x -= 3 #5

x %= 2 #1

x /= 1 #1.0

1 Like

Re: Learning Programming. (my Nairaland Journal) by Karleb(m): 6:28pm On Nov 28, 2020
In python for loop, the range function doesn't loop to the end of the value naturally, to enable it do this, you have to add 1 the value.


range(1, 4) will print out. 1,2,3 in a loop. So to let it loop to 4 you'll add 1 to 4 to make it 5.


That is, range(1, 4 + 1) will print 1,2,3,4. That is thesame thing as range(1, 5).


In the case where the integer is stored in a variable is when you see something like range(1, myValue + 1).


myValue = 4
for i in range(1, myValue + 1):
print(i)


That loop will print 1,2,3,4.


I think this range thingy is a bug turned feature in python because when you loop through a list, you don't have this problem.
Re: Learning Programming. (my Nairaland Journal) by naijasensei: 6:31pm On Nov 28, 2020
syluck:


Bro, there's this python concepts I really need to understand how it works....
I'll list then below:

1: for i in range (2, prompt+1):

Here, I know "prompt" could be a variable where a value is assigned to.....then, (2) is where we want the loop to start from.... My difficulty is understanding what +1 after the prompt stands for....
Like the example above I listed is used when running a code for "divisors of a number*...

2: for i range(1, num+1):
Indent""""""""factorial = factorial * i

Here, the +1 appears again.... But this time around it's the "factorial * i".... Pls I need to understand this concept really good.....

Lastly:

3: for i in range(1, prompt+1):
Indent"""""""""if(prompt %i ==0)
Indent"""""""""s += i

Here, I understand what prompt is, %i is, ==0 is, and s is... The problem is, "+=". I still don't understand vividly what's that all about...in short, u can explain the whole concept "s += i" to me please....

PS: i know that
+ is an addition operator
* Is a multiplication operator
= a equal sign operator ( mostly used to assign values to variables and vice versa)

Q1 - First understand what range() does.
range(start, stop, step). The range function produces values from the start value, upto but NOT INCLUDING the stop value. That is;
for i in range(1,10)
supplies i with values 1,2,3,4,5,6,7,8,9. Assuming prompt = 10, and I want a range of values from 1 to 10 (10 inclusive), instead of range(1, prompt) I would rather use range(1, prompt + 1)

Q2 - factorial = factorial * i is a programming concept you will see a lot of. It means multiply the value referenced by "i" with the current value referenced by "factorial", then let the new value referenced by factorial be (factorial * i)

Q3 - s += i is the same as s = s + i, same explanation as in Q2

s *= i is the same as s = s * i,
s -= i is the same as s = s - i,
and so on.

1 Like

Re: Learning Programming. (my Nairaland Journal) by syluck(m): 8:24pm On Nov 28, 2020
Karleb:
In python for loop, the range function doesn't loop to the end of the value naturally, to enable it do this, you have to add 1 the value.


range(1, 4) will print out. 1,2,3 in a loop. So to let it loop to 4 you'll add 1 to 4 to make it 5.


That is, range(1, 4 + 1) will print 1,2,3,4. That is thesame thing as range(1, 5).


In the case where the integer is stored in a variable is when you see something like range(1, myValue + 1).


myValue = 4
for i in range(1, myValue + 1):
print(i)


That loop will print 1,2,3,4.


I think this range thingy is a bug turned feature in python because when you loop through a list, you don't have this problem.
I appreciate this thanks....

(1) (2) (3) (4) (5) (6) (7) (8) (9) (Reply)

Whats The Best Laptop For Programming? / Best Operating System For Programming! / Testing Programmers: Puzzles Or Web Applications?

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 75
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.