aboutsummaryrefslogtreecommitdiff
path: root/challenge-273/spadacciniweb/python/ch-1.py
diff options
context:
space:
mode:
authorATSchneider <atschneider@temple.edu>2024-06-16 07:37:39 -0400
committerGitHub <noreply@github.com>2024-06-16 07:37:39 -0400
commitbd67c7d68d54058bc6bc6b41ae8bbc8de725314f (patch)
treeb19053d19cd2c6952b1677e099c20e03ca63f19d /challenge-273/spadacciniweb/python/ch-1.py
parent86f02124512baeea87ccccea67dc73bab9db71ca (diff)
parente7c6e4694cbc20e39268624c74ec9d5134bd66b7 (diff)
downloadperlweeklychallenge-club-bd67c7d68d54058bc6bc6b41ae8bbc8de725314f.tar.gz
perlweeklychallenge-club-bd67c7d68d54058bc6bc6b41ae8bbc8de725314f.tar.bz2
perlweeklychallenge-club-bd67c7d68d54058bc6bc6b41ae8bbc8de725314f.zip
Merge branch 'manwar:master' into master
Diffstat (limited to 'challenge-273/spadacciniweb/python/ch-1.py')
-rw-r--r--challenge-273/spadacciniweb/python/ch-1.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/challenge-273/spadacciniweb/python/ch-1.py b/challenge-273/spadacciniweb/python/ch-1.py
new file mode 100644
index 0000000000..bfbc5cbc57
--- /dev/null
+++ b/challenge-273/spadacciniweb/python/ch-1.py
@@ -0,0 +1,61 @@
+# Task 1: Percentage of Character
+# Submitted by: Mohammad Sajid Anwar
+#
+# You are given a string, $str and a character $char.
+# Write a script to return the percentage, nearest whole, of given character in the given string.
+#
+# Example 1
+# Input: $str = "perl", $char = "e"
+# Output: 25
+#
+# Example 2
+# Input: $str = "java", $char = "a"
+# Output: 50
+#
+# Example 3
+# Input: $str = "python", $char = "m"
+# Output: 0
+#
+# Example 4
+# Input: $str = "ada", $char = "a"
+# Output: 67
+#
+# Example 5
+# Input: $str = "ballerina", $char = "l"
+# Output: 22
+#
+# Example 6
+# Input: $str = "analitik", $char = "k"
+# Output: 13
+
+def percentage(str, char):
+ print("%s -> %d" %
+ ( str,
+ round( str.count(char)*100/len(str) )
+ )
+ )
+
+if __name__ == "__main__":
+ str = "perl"
+ char = "e"
+ percentage(str, char)
+
+ str = "java"
+ char = "a"
+ percentage(str, char)
+
+ str = "python"
+ char = "m"
+ percentage(str, char)
+
+ str = "ada"
+ char = "a"
+ percentage(str, char)
+
+ str = "ballerina"
+ char = "l"
+ percentage(str, char)
+
+ str = "analitik"
+ char = "k"
+ percentage(str, char)