feat: reformatted 1.29 and 1.30 with black
This commit is contained in:
Generated
+4
-6
@@ -1,12 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<module type="PYTHON_MODULE" version="4">
|
<module type="PYTHON_MODULE" version="4">
|
||||||
<component name="NewModuleRootManager">
|
<component name="NewModuleRootManager">
|
||||||
<content url="file://$MODULE_DIR$" />
|
<content url="file://$MODULE_DIR$">
|
||||||
<orderEntry type="jdk" jdkName="~/anaconda3/envs/cybr108" jdkType="Python SDK" />
|
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="jdk" jdkName="~/.conda/envs/josephroot" jdkType="Python SDK" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
</component>
|
</component>
|
||||||
<component name="PackageRequirementsSettings" />
|
|
||||||
<component name="PyDocumentationSettings" />
|
|
||||||
<component name="ReSTService" />
|
|
||||||
<component name="TestRunnerService" />
|
|
||||||
</module>
|
</module>
|
||||||
+5
-3
@@ -2,6 +2,8 @@
|
|||||||
Write a Python program that outputs all possible strings formed by using the characters 'c', 'a', 't', 'd', 'o', and 'g'
|
Write a Python program that outputs all possible strings formed by using the characters 'c', 'a', 't', 'd', 'o', and 'g'
|
||||||
exactly once.
|
exactly once.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
# define 'permute' function
|
# define 'permute' function
|
||||||
def permute(char_pool, current_str):
|
def permute(char_pool, current_str):
|
||||||
# base case: if char_pool is empty, print value of 'current_str'
|
# base case: if char_pool is empty, print value of 'current_str'
|
||||||
@@ -11,7 +13,7 @@ def permute(char_pool, current_str):
|
|||||||
# try each remaining character as the next pick
|
# try each remaining character as the next pick
|
||||||
for i in range(len(char_pool)):
|
for i in range(len(char_pool)):
|
||||||
# pick character at i: pass down pool without it, and string with it added
|
# pick character at i: pass down pool without it, and string with it added
|
||||||
permute(char_pool[:i] + char_pool[i+1:], current_str + char_pool[i])
|
permute(char_pool[:i] + char_pool[i + 1 :], current_str + char_pool[i])
|
||||||
|
|
||||||
|
|
||||||
permute('catdog', '')
|
|
||||||
|
permute("catdog", "")
|
||||||
|
|||||||
+7
-6
@@ -3,20 +3,21 @@ Write a Python program that can take a positive integer greater than 2 as input
|
|||||||
one must repeatedly divide this number by 2 before getting a value less than 2.
|
one must repeatedly divide this number by 2 before getting a value less than 2.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def count_steps():
|
def count_steps():
|
||||||
# input validation: try that input is an integer
|
# input validation: try that input is an integer
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
current_value = int(input('Please enter an integer greater than 2: '))
|
current_value = int(input("Please enter an integer greater than 2: "))
|
||||||
# also try that input is above 2, if not print error message
|
# also try that input is above 2, if not print error message
|
||||||
if current_value <= 2:
|
if current_value <= 2:
|
||||||
print('Invalid input: Please enter only integers greater than 2.')
|
print("Invalid input: Please enter only integers greater than 2.")
|
||||||
# if input is correct, break the while loop
|
# if input is correct, break the while loop
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
# Handle ValueError and print error message
|
# Handle ValueError and print error message
|
||||||
except ValueError:
|
except ValueError:
|
||||||
print('Invalid input: Please only enter integers.')
|
print("Invalid input: Please only enter integers.")
|
||||||
|
|
||||||
# set 'step_count' variable to count divisions
|
# set 'step_count' variable to count divisions
|
||||||
step_count = 0
|
step_count = 0
|
||||||
@@ -28,4 +29,4 @@ def count_steps():
|
|||||||
print(step_count)
|
print(step_count)
|
||||||
|
|
||||||
|
|
||||||
count_steps()
|
count_steps()
|
||||||
|
|||||||
Reference in New Issue
Block a user