|
847 | 847 | }, |
848 | 848 | { |
849 | 849 | "cell_type": "code", |
850 | | - "execution_count": 21, |
| 850 | + "execution_count": 9, |
851 | 851 | "metadata": {}, |
852 | | - "outputs": [ |
853 | | - { |
854 | | - "data": { |
855 | | - "text/plain": [ |
856 | | - "False" |
857 | | - ] |
858 | | - }, |
859 | | - "execution_count": 21, |
860 | | - "metadata": {}, |
861 | | - "output_type": "execute_result" |
862 | | - } |
863 | | - ], |
| 852 | + "outputs": [], |
864 | 853 | "source": [ |
865 | 854 | "num = 1\n", |
866 | | - "num > 3" |
| 855 | + "if num > 3 :\n", |
| 856 | + " print(\"Hi\")" |
867 | 857 | ] |
868 | 858 | }, |
869 | 859 | { |
870 | 860 | "cell_type": "code", |
871 | | - "execution_count": 4, |
| 861 | + "execution_count": 10, |
872 | 862 | "metadata": {}, |
873 | 863 | "outputs": [ |
874 | 864 | { |
|
892 | 882 | }, |
893 | 883 | { |
894 | 884 | "cell_type": "code", |
895 | | - "execution_count": 5, |
| 885 | + "execution_count": 11, |
896 | 886 | "metadata": {}, |
897 | 887 | "outputs": [ |
898 | 888 | { |
|
912 | 902 | " print(\"number is not greater than 3\")" |
913 | 903 | ] |
914 | 904 | }, |
915 | | - { |
916 | | - "cell_type": "code", |
917 | | - "execution_count": null, |
918 | | - "metadata": { |
919 | | - "collapsed": true |
920 | | - }, |
921 | | - "outputs": [], |
922 | | - "source": [ |
923 | | - "# Modulo (%)\n", |
924 | | - "# Returns the remainder of the division of the number to the left by the \n", |
925 | | - "# number on its right. " |
926 | | - ] |
927 | | - }, |
928 | 905 | { |
929 | 906 | "cell_type": "markdown", |
930 | 907 | "metadata": {}, |
|
944 | 921 | "cell_type": "markdown", |
945 | 922 | "metadata": {}, |
946 | 923 | "source": [ |
947 | | - "Hint: Any integer that can be divided exactly by 2 is an even number (examples: 2, 4, 6). Any integer that cannot be divided exactly by 2 is an odd number (examples: 1, 3, 5)." |
| 924 | + "Hint: Any integer that can be divided exactly by 2 is an even number (examples: 2, 4, 6). Any integer that cannot be divided exactly by 2 is an odd number (examples: 1, 3, 5). Use the modulo operator (%) which returns the remainder of the division of the number to the left by the number on its right. \n" |
948 | 925 | ] |
949 | 926 | }, |
950 | 927 | { |
951 | 928 | "cell_type": "code", |
952 | | - "execution_count": 10, |
| 929 | + "execution_count": 12, |
953 | 930 | "metadata": {}, |
954 | 931 | "outputs": [ |
955 | 932 | { |
956 | | - "name": "stdout", |
957 | | - "output_type": "stream", |
958 | | - "text": [ |
959 | | - "Your integer is even\n" |
960 | | - ] |
| 933 | + "data": { |
| 934 | + "text/plain": [ |
| 935 | + "0" |
| 936 | + ] |
| 937 | + }, |
| 938 | + "execution_count": 12, |
| 939 | + "metadata": {}, |
| 940 | + "output_type": "execute_result" |
961 | 941 | } |
962 | 942 | ], |
963 | 943 | "source": [ |
964 | | - "my_num = 2\n", |
965 | | - "if my_num % 2 == 0:\n", |
966 | | - " print(\"Your integer is even\")\n", |
967 | | - "else: \n", |
968 | | - " print(\"Your number is odd\")" |
| 944 | + "4 % 2 " |
969 | 945 | ] |
970 | 946 | }, |
971 | 947 | { |
972 | | - "cell_type": "markdown", |
973 | | - "metadata": {}, |
974 | | - "source": [ |
975 | | - "explanation: Modulo (%) returns the remainder of the division of the number to the left by the number on its right. " |
976 | | - ] |
| 948 | + "cell_type": "code", |
| 949 | + "execution_count": null, |
| 950 | + "metadata": { |
| 951 | + "collapsed": true |
| 952 | + }, |
| 953 | + "outputs": [], |
| 954 | + "source": [] |
977 | 955 | }, |
978 | 956 | { |
979 | 957 | "cell_type": "code", |
980 | | - "execution_count": 6, |
| 958 | + "execution_count": null, |
981 | 959 | "metadata": { |
982 | 960 | "collapsed": true |
983 | 961 | }, |
984 | 962 | "outputs": [], |
985 | | - "source": [ |
986 | | - "?type" |
987 | | - ] |
| 963 | + "source": [] |
988 | 964 | }, |
989 | 965 | { |
990 | 966 | "cell_type": "code", |
991 | | - "execution_count": 7, |
992 | | - "metadata": {}, |
993 | | - "outputs": [ |
994 | | - { |
995 | | - "data": { |
996 | | - "text/plain": [ |
997 | | - "True" |
998 | | - ] |
999 | | - }, |
1000 | | - "execution_count": 7, |
1001 | | - "metadata": {}, |
1002 | | - "output_type": "execute_result" |
1003 | | - } |
1004 | | - ], |
1005 | | - "source": [ |
1006 | | - "4 % 2\n", |
1007 | | - "True and True" |
1008 | | - ] |
| 967 | + "execution_count": null, |
| 968 | + "metadata": { |
| 969 | + "collapsed": true |
| 970 | + }, |
| 971 | + "outputs": [], |
| 972 | + "source": [] |
| 973 | + }, |
| 974 | + { |
| 975 | + "cell_type": "code", |
| 976 | + "execution_count": null, |
| 977 | + "metadata": { |
| 978 | + "collapsed": true |
| 979 | + }, |
| 980 | + "outputs": [], |
| 981 | + "source": [] |
1009 | 982 | }, |
1010 | 983 | { |
1011 | 984 | "cell_type": "code", |
|
1016 | 989 | "name": "stdout", |
1017 | 990 | "output_type": "stream", |
1018 | 991 | "text": [ |
1019 | | - "Your number is most likely odd (assuming it isn't a float)\n" |
| 992 | + "Your number is odd\n" |
1020 | 993 | ] |
1021 | 994 | } |
1022 | 995 | ], |
1023 | 996 | "source": [ |
1024 | 997 | "my_num = 3\n", |
1025 | | - "if type(my_num) == \"int\" and my_num % 2 == 0:\n", |
1026 | | - " print(\"Your number is even\")\n", |
| 998 | + "if my_num % 2 == 0:\n", |
| 999 | + " print(\"Your integer is even\")\n", |
1027 | 1000 | "else: \n", |
1028 | | - " print(\"Your number is most likely odd (assuming it isn\\'t a float)\")" |
| 1001 | + " print(\"Your integer is odd\")" |
1029 | 1002 | ] |
1030 | 1003 | }, |
1031 | 1004 | { |
|
0 commit comments