Some simple exercises and Python exercises for new python beginners

Source: Internet
Author: User

Some simple exercises and Python exercises for new python beginners

Preface

This article mainly shares some simple Python exercises, which is a good exercise for beginners who are learning python. I will not talk about them much below. Let's take a look at the detailed introduction.

Question 1: Use a while loop to input 1 2 3 4 5 6 8 9 10

a = 0while a < 10: a +=1  if a == 7:  continue print(a)

Question 2: Calculate the sum of all numbers from 1

Method 1:

a = 0b = 1while b <= 100: a = a + b b += 1print(a)

Method 2:

a = 0for i in range(101):  a = a + i  print(a)

Question 3: output all odd numbers in 1-100

a = 0while a <= 100: a += 1 if(a%2) == 0:  print(a)

Question 4: output all even numbers in 1-100

Method 1:

a = 0while a <= 100:  a += 1  if(a%2) == 0:    print(a-2+1)

Method 2:

a = 0while a <= 99:  a += 1  if(a%2) != 0:    print(a)

Question 5: Calculate the sum of all numbers of 1-2 + 3-4 + 5... 99

a = 0b = 0while a < 99:  a += 1  if a%2 == 1:   b += a  else:   b -= aprint(b)

Question 6: User Login (three chances to retry)

A = 0 while a <3: name = input ("Enter the User name:") password = input ("enter the password :") a + = 1 if name = 'wxd 'and password = '000000': print ("Login successful") exit () else: print ("input error, enter ") print (" three input errors, exit ") again ")

Summary

The above is all the content of this article. I hope the content of this article will help you in your study or work. If you have any questions, please leave a message, thank you for your support.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.