Skip to content

Instantly share code, notes, and snippets.

View iyashjayesh's full-sized avatar
🥇
Creating! Building! Inspiring!

Yash Chauhan iyashjayesh

🥇
Creating! Building! Inspiring!
View GitHub Profile
@iyashjayesh
iyashjayesh / main.py
Created April 16, 2020 20:12
Write a program to prompt the user for hours and rate per hour using input to compute gross pay. Pay the hourly rate for the hours up to 40 and 1.5 times the hourly rate for all hours worked above 40 hours. Use 45 hours and a rate of 10.50 per hour to test the program (the pay should be 498.75). You should use input to read a string and float()…
hrs = float(input("Enter Hours:"))
rate = float(input("Enter the Rate:"))
if hrs <= 40:
print( hrs * rate)
elif hrs > 40:
print(40* rate + (hrs-40)*1.5*rate)
@iyashjayesh
iyashjayesh / main.py
Last active April 16, 2020 20:21
Write a program to prompt for a score between 0.0 and 1.0. If the score is out of range, print an error. If the score is between 0.0 and 1.0, print a grade using the following table: Score Grade >= 0.9 A >= 0.8 B >= 0.7 C >= 0.6 D < 0.6 F If the user enters a value out of range, print a suitable error message and exit. For the test, enter a scor…
score = float(input("enter a score:"))
s = score
if 0.0 <= s <= 1.0:
if s >= 0.9:
result = "A"
print(result)
elif 0.8 <= s < 0.9:
result = "B"
@iyashjayesh
iyashjayesh / main.py
Created April 16, 2020 21:04
Write a program to prompt the user for hours and rate per hour using input to compute gross pay. Pay should be the normal rate for hours up to 40 and time-and-a-half for the hourly rate for all hours worked above 40 hours. Put the logic to do the computation of pay in a function called computepay() and use the function to do the computation. The…
def computepay(h, r):
if h > 40:
p = 1.5 * r * (h - 40) + (40 * r)
else:
p = h * r
return p
hrs = float(input("Enter Hours:"))
rphrs = float(input("Enter rate per hour:"))
@iyashjayesh
iyashjayesh / main.py
Created April 16, 2020 22:25
Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'. Once 'done' is entered, print out the largest and smallest of the numbers. If the user enters anything other than a valid number catch it with a try/except and put out an appropriate message and ignore the number. Enter 7, 2, bob, 10, and 4 and match…
largest = None
smallest = None
while True:
num = input("Enter a number: ")
if num == "done":
break
try:
n = int(num)
if smallest is None or n < smallest:
@iyashjayesh
iyashjayesh / juggling_algorithm.cpp
Created July 18, 2020 07:01
Array Rotation - juggling Algorithm O(n)
#include<bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < n; i++)
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define lli long long int
@iyashjayesh
iyashjayesh / onebyone_rotate.cpp
Created July 18, 2020 07:28
One by One rotation of Array - Time Complexity O(n*d)
// C++ program to rotate an array by d elements
#include <bits/stdc++.h>
using namespace std;
/*Function to left Rotate arr[] of size n by 1*/
void leftRotatebyOne(int arr[], int n)
{
int temp = arr[0], i;
for (i = 0; i < n - 1; i++)
arr[i] = arr[i + 1];
@iyashjayesh
iyashjayesh / main.go
Created June 30, 2022 05:45
Program to get the IP Address and Hostname
package main
import (
"log"
"net"
"os"
)
func main() {
hostname, _ := os.Hostname() // get hostname
addrs, err := net.LookupIP(hostname) // returns a slice of the IP addresses of the host
// lookupIP looks up host using the local resolver. It returns a slice of that host's IPv4 and IPv6 addresses.
@iyashjayesh
iyashjayesh / main.java
Created June 30, 2022 06:09
Java Program to get Ip address and Hostname
import java.io.*;
import java.net.*;
public class InetSampleCode {
public static void main(String[] args) {
try {
InetAddress id = InetAddress.getLocalHost();
System.out.println("Host Name: " + id.getHostName());
System.out.println("IP Address: " + id.getHostAddress());
} catch (Exception e) {
@iyashjayesh
iyashjayesh / main.go
Last active June 30, 2022 07:12
How to use Time package to get Time & date in various formats.
// You can edit this code!
package main
import (
"log"
"time"
)
func main() {
// get current time in UTC timezone
@iyashjayesh
iyashjayesh / main.go
Last active June 30, 2022 10:59
Golang Logrus Simple Implementation
package main
import (
"github.com/sirupsen/logrus"
)
func main() {
var log = logrus.New()
log.SetFormatter(&logrus.JSONFormatter{
// DisableTimestamp: false, // Default: false