{"id":1304,"date":"2024-12-27T14:54:41","date_gmt":"2024-12-27T13:54:41","guid":{"rendered":"https:\/\/vroamam.com\/wordpress\/?p=1304"},"modified":"2024-12-27T14:54:41","modified_gmt":"2024-12-27T13:54:41","slug":"day-4-randomisation-and-python-lists","status":"publish","type":"post","link":"https:\/\/vroamam.com\/wordpress\/blog\/day-4-randomisation-and-python-lists\/","title":{"rendered":"Day 4 Randomisation and Python Lists"},"content":{"rendered":"\n<ul class=\"wp-block-list\">\n<li>Day 4 goals<\/li>\n\n\n\n<li>Random Module<\/li>\n\n\n\n<li>Lists\n<ul class=\"wp-block-list\">\n<li>Appending<\/li>\n\n\n\n<li>Offset<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Coding Exercise: Who will pay the bill?<\/li>\n\n\n\n<li>Index Errors and Nested Lists<\/li>\n\n\n\n<li>Project: Rock-Paper-Scissors<\/li>\n<\/ul>\n\n\n\n<p>My &#8220;Pay the Bill&#8221; exercise<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import random\nfriends = &#91;\"Alice\", \"Bob\", \"Charlie\", \"David\", \"Emanuel\"]\n\n# this was my \"old fashioned\" solution\nchoice = random.randint(0, 4)\nprint(friends&#91;choice])\n\n# this was Angela's solution\n# print(random.choice(friends))<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>My Project: Rick-Paper-Scissors<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rock = '''\n    _______\n---'   ____)\n      (_____)\n      (_____)\n      (____)\n---.__(___)\n'''\n\npaper = '''\n    _______\n---'   ____)____\n          ______)\n          _______)\n         _______)\n---.__________)\n'''\n\nscissors = '''\n    _______\n---'   ____)____\n          ______)\n       __________)\n      (____)\n---.__(___)\n'''\n\n''' \n# the line above was added because the theme does not understand the three single apostrophes. Remove this if you are copying this code.\n\nimport random\n\ngame_images = &#91;rock, paper, scissors]\n\n# get the users selection\nuser_choice = int(input(\"What do you choose? Type 0 for Rock, 1 for Paper or 2 for Scissors.\\n\"))\nif user_choice >= 0 and user_choice &lt;= 2:\n    print(\"You chose:\")\n    print(game_images&#91;user_choice])\nelse:\n    print(\"You typed an invalid number. You lose!\")\n    exit()\n\n#get the computers choice\ncomputer_choice = random.randint(0, 2)\nprint(\"Computer chose:\")\nprint(game_images&#91;computer_choice])\n\n# do the comparison\nif user_choice == 0 and computer_choice == 2:\n    print(\"You win!\")\nelif  computer_choice == 0 and user_choice == 2:\n    print(\"You lose!\")\nelif user_choice > computer_choice:\n    print(\"You win!\")\nelif computer_choice > user_choice:\n    print(\"You lose!\")\nelse:\n    print(\"It's a draw!\")\n\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>My &#8220;Pay the Bill&#8221; exercise My Project: Rick-Paper-Scissors<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"","ocean_second_sidebar":"","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"","ocean_custom_header_template":"","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"","ocean_menu_typo_font_family":"","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"on","ocean_gallery_id":[],"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[144,148,3],"tags":[146,145,11],"class_list":["post-1304","post","type-post","status-publish","format-standard","hentry","category-100daysofcode","category-python","category-training","tag-100daysofcode","tag-python","tag-training","entry"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pahuGk-l2","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/posts\/1304","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/comments?post=1304"}],"version-history":[{"count":8,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/posts\/1304\/revisions"}],"predecessor-version":[{"id":1313,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/posts\/1304\/revisions\/1313"}],"wp:attachment":[{"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/media?parent=1304"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/categories?post=1304"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vroamam.com\/wordpress\/wp-json\/wp\/v2\/tags?post=1304"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}