Errors and errors | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Errors and errors

The population of rabbits at a lab doubles every year. The lab was started initially with 7 rabbits. Your program needs to calculate the number of rabbits you will have after the number of years provided as input.

30th Jun 2021, 5:51 PM
Chinmay Anand
Chinmay Anand - avatar
11 Answers
+ 2
Chinmay Anand Review the loops lesson just prior to this practice. Start with 7 rabbits. You need to loop years times (get years as an input). Inside the loop double the amount of rabbits (rabbits = rabbits * 2) and set the new amount back to the rabbits variable. After the loop output the amount of rabbits.
30th Jun 2021, 8:20 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
rabbits * 2**years
30th Jun 2021, 5:59 PM
Oma Falk
Oma Falk - avatar
+ 1
Atul [Inactive] it is simply the formula
30th Jun 2021, 7:06 PM
Oma Falk
Oma Falk - avatar
+ 1
Here is my attempt, but it says my loop syntax is wrong. Can anyone help? package main import "fmt" func main() { var years int fmt.Scanln(&years) //your code goes here start:=7 i:=2 for start := 7; i<years; i++ { start =start*i** years fmt.Println(start) } }
27th Oct 2021, 4:28 PM
Rafique
Rafique - avatar
+ 1
package main import "fmt" func main() { var years int fmt.Scanln(&years) rabbits := 7 //your code goes here for i := 0; i < years; i++ { rabbits *= 2 } fmt.Println(rabbits) }
8th May 2023, 8:34 AM
MUHAMMAD IQBAL ARRASYID
MUHAMMAD IQBAL ARRASYID - avatar
0
Post your code here
30th Jun 2021, 6:24 PM
Atul [Inactive]
0
Oma Falk Is this valid in Golang also?
30th Jun 2021, 6:29 PM
Atul [Inactive]
0
Thanks.
1st Jul 2021, 3:37 AM
Chinmay Anand
Chinmay Anand - avatar
0
It is in golang
1st Sep 2021, 6:09 AM
Rachel
Rachel - avatar
0
Can someone please help
1st Sep 2021, 6:09 AM
Rachel
Rachel - avatar
0
package main import "fmt" func main() { var years int fmt.Scanln(&years) pow := make([]int, years ) for i:= range pow { pow[i] = 7 << uint(i) // == 2**i } for _, value := range pow { fmt.Printf("%d\n" ,value) } } any one can help reduce the number of range of values to print the last number of year cause mine a whole range of years 😂😋
9th Feb 2022, 2:39 PM
princeps ludwig
princeps ludwig - avatar