Advance programming with R
Advance programming with R
1) Aamir is an hourly paid employee, and he is paid 250/hr for 9 hrs shi . If he works extra for 5 hrs or less in a week than
he will get 250/hr for extra hours, if no. of hrs is less than equal to 10 hrs than 1.5 mes of hourly pay if above that then
2 mes of hourly pay. Calculate the monthly wage of Aamir taking into account the no. of leaves taken in month and PF
deduc on (5% of total monthly salary). Create a func on to perform above calcula on.
Monthly salary = (No. of daily hours * cost of per hour) + (extra hrs * cost as per above men oned rules)
In hand salary = Monthly salary – (leaves taken* 250) – PF (5% of Monthly salary)
2) Create a vector named Numbers which will have numbers from 1 to 500 and perform below given tasks using R code
Q. 4) Write R code for a game where a random numer is generated between 1 to 5 and user is asked to guess the number
repeatedly un ll he guess the right number. In this If user guess the number correctly then a message will be printed
on screen saying “Congratula ons your guess is correct” else user will see two di erent message where rst will be
“Your guess is not correct” and second will be a ques on asking “Would you like to try again?” if user quits the game
message will be shown saying “You qui ed the game”. Below is the screenshot of outcome.
Note : - The game will end only if user doesn’t want to try again or guess the number correctly. Also print the guessed
and correct number for correct and incorrect guesses as shown below in screenshot.
ti
ti
tt
ti
ff
fi
Q.5) Below is the informa on on products and their prices for single quan ty
Juice – 50, Sugar – 40, Toothpaste – 80, Oven – 1200, Mixer – 1200, Ketchup – 150, Pickle – 95, Door mat – 200,
Curtains – 500, Bo les – 110, Salt – 25, Spices – 150, Chocolates – 250, Biscuits – 130, School bag – 600, Umbrella –
300, Toaster – 1300, Jam – 60, Dry fruits – 500, Perfume – 700
Below is the vector of items purchased by a customer
Calculate the total bill of customer based on the price of product and quan ty purchased. Sample output is shown
below.
Note: - The nal output should be in above format and also products which are not available like milkshakes and
vaccum cleaner in above case hyphen (-) should be shown in nal output data as shown above.
fi
tt
ti
fi
tt
ti
ti
# creating dataframe for product and price
#total bill
# renaming columns