Skip to content

Commit 86dc24c

Browse files
committed
Solutions for Jungle Camping and Pig Latin
1 parent d3d7df3 commit 86dc24c

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

Python/JungleCamping.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Jungle Camping +10 XP
2+
3+
##############################
4+
#### Problem Description #####
5+
##############################
6+
7+
# You are camping alone out in the jungle and you hear some animals in the dark nearby. Based on the noise they make, determine which animals they are.
8+
9+
# Task:
10+
# You are given the noises made by different animals that you can hear in the dark, evaluate each noise to determine which animal it belongs to. Lions say 'Grr', Tigers say 'Rawr', Snakes say 'Ssss', and Birds say 'Chirp'.
11+
12+
# Input Format:
13+
# A string that represent the noises that you hear with a space between them.
14+
15+
# Output Format:
16+
# A string that includes each animal that you hear with a space after each one. (animals can repeat)
17+
18+
# Sample Input:
19+
# Rawr Chirp Ssss
20+
21+
# Sample Output:
22+
# Tiger Bird Snake
23+
24+
##############################
25+
########## Solution ##########
26+
##############################
27+
28+
# Create a dictionary of animal sounds based on the problem description
29+
animalSoundsDict = {
30+
"Grr": "Lion",
31+
"Rawr": "Tiger",
32+
"Ssss": "Snake",
33+
"Chirp": "Bird"
34+
}
35+
36+
# Take Sololearn input
37+
animalSounds = input()
38+
# Split the string into list on the default delimiter value of any white space
39+
animalSoundsList = animalSounds.split()
40+
41+
# Create a new list to store the animals heard.
42+
animalsHeardList = []
43+
44+
# Loop through each item in the list
45+
for animalSound in animalSoundsList:
46+
# Look in the animalSoundsDict to get the current animal sound.
47+
animalsHeardList.append(animalSoundsDict[animalSound])
48+
# This could also be done with an If statement (i.e. if animalSound == "Grr": "Lion" ...etc)
49+
50+
# Join the new array together with a space in between each
51+
animalsHeard = " ".join(animalsHeardList)
52+
print(animalsHeard)

Python/PigLatin.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Pig Latin +50 XP
2+
3+
##############################
4+
#### Problem Description #####
5+
##############################
6+
7+
# You have two friends who are speaking Pig Latin to each other! Pig Latin is the same words in the same order except that you take the first letter of each word and put it on the end, then you add 'ay' to the end of that. ("road" = "oadray")
8+
9+
# Task
10+
# Your task is to take a sentence in English and turn it into the same sentence in Pig Latin!
11+
12+
# Input Format
13+
# A string of the sentence in English that you need to translate into Pig Latin. (no punctuation or capitalization)
14+
15+
# Output Format
16+
# A string of the same sentence in Pig Latin.
17+
18+
# Sample Input
19+
# "nevermind youve got them"
20+
21+
# Sample Output
22+
# "evermindnay ouveyay otgay hemtay"
23+
24+
##############################
25+
########## Solution ##########
26+
##############################
27+
28+
# Take Sololearn input
29+
startingSting = input()
30+
# Split the string into list on the default delimiter value of any white space
31+
stringSplit = startingSting.split()
32+
33+
# Loop through each item in the list
34+
for i in range(len(stringSplit)):
35+
# Replace the current item with the pig latin version.
36+
# stringSplit[i][1:] is 2nd character of string through end
37+
# stringSplit[i][0:1] is 1st character of string
38+
# An "ay" is concatinated at the end of the new string
39+
stringSplit[i] = stringSplit[i][1:] + stringSplit[i][0:1] + "ay"
40+
41+
# Join the new array together with a space in between each
42+
finalString = " ".join(stringSplit)
43+
print(finalString)

0 commit comments

Comments
 (0)