Skip to content

Commit 65f4751

Browse files
golang code files
0 parents  commit 65f4751

File tree

79 files changed

+4601
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+4601
-0
lines changed

01hello/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module hello
2+
3+
go 1.17

01hello/main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package main
2+
3+
import "fmt"
4+
5+
func main() {
6+
fmt.Println("Hello from LearnCodeonline.in")
7+
}

02variables/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module variables
2+
3+
go 1.17

02variables/main.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package main
2+
3+
import "fmt"
4+
5+
const LoginToken string = "ghabbhhjd" // Public
6+
7+
func main() {
8+
var username string = "hitesh"
9+
fmt.Println(username)
10+
fmt.Printf("Variable is of type: %T \n", username)
11+
12+
var isLoggedIn bool = false
13+
fmt.Println(isLoggedIn)
14+
fmt.Printf("Variable is of type: %T \n", isLoggedIn)
15+
16+
var smallVal uint8 = 255
17+
fmt.Println(smallVal)
18+
fmt.Printf("Variable is of type: %T \n", smallVal)
19+
20+
var smallFloat float64 = 255.45544511254451885
21+
fmt.Println(smallFloat)
22+
fmt.Printf("Variable is of type: %T \n", smallFloat)
23+
24+
// default values and some aliases
25+
var anotherVariable int
26+
fmt.Println(anotherVariable)
27+
fmt.Printf("Variable is of type: %T \n", anotherVariable)
28+
29+
// implicit type
30+
31+
var website = "learncodeonline.in"
32+
fmt.Println(website)
33+
34+
// no var style
35+
36+
numberOfUser := 300000.0
37+
fmt.Println(numberOfUser)
38+
39+
fmt.Println(LoginToken)
40+
fmt.Printf("Variable is of type: %T \n", LoginToken)
41+
42+
}

03userinput/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module userinput
2+
3+
go 1.17

03userinput/main.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
"fmt"
6+
"os"
7+
)
8+
9+
func main() {
10+
welcome := "Welcome to user input"
11+
fmt.Println(welcome)
12+
13+
reader := bufio.NewReader(os.Stdin)
14+
fmt.Println("Enter the rating for our Pizza:")
15+
16+
// comma ok || err err
17+
18+
input, _ := reader.ReadString('\n')
19+
fmt.Println("Thanks for rating, ", input)
20+
fmt.Printf("Type of this rating is %T", input)
21+
}

04conversion/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module conversion
2+
3+
go 1.17

04conversion/main.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
"fmt"
6+
"os"
7+
"strconv"
8+
"strings"
9+
)
10+
11+
func main() {
12+
fmt.Println("Welcome to our pizza app")
13+
fmt.Println("Please rate our pizza between 1 and 5")
14+
15+
reader := bufio.NewReader(os.Stdin)
16+
17+
input, _ := reader.ReadString('\n')
18+
19+
fmt.Println("Thanks for rating, ", input)
20+
21+
numRating, err := strconv.ParseFloat(strings.TrimSpace(input), 64)
22+
23+
if err != nil {
24+
fmt.Println(err)
25+
26+
} else {
27+
fmt.Println("Added 1 to your rating: ", numRating+1)
28+
}
29+
}

05mymaths/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module mymath
2+
3+
go 1.17

05mymaths/main.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"math/big"
6+
7+
//"math/rand"
8+
"crypto/rand"
9+
)
10+
11+
func main() {
12+
fmt.Println("Welcome to maths in golang")
13+
14+
//var mynumberOne int = 2
15+
//var mynumberTwo float64 = 4.5
16+
17+
// fmt.Println("The sum is: ", mynumberOne+int(mynumberTwo))
18+
19+
//random number
20+
// rand.Seed(time.Now().UnixNano())
21+
// fmt.Println(rand.Intn(5) + 1)
22+
23+
//random from crypto
24+
25+
myRandomNum, _ := rand.Int(rand.Reader, big.NewInt(5))
26+
fmt.Println(myRandomNum)
27+
28+
}

0 commit comments

Comments
 (0)