The second problem: calculating all the numbers in a string and1. Only lowercase letters and numbers in a string2. Numbers may or may not be contiguous3. Sequential numbers are treated as a numbers= ' 1234adg3g11 'S1 = ""For I in S: If I.isdigit (): S1=s1+i Else s1=s1+ ""lt = S1.split ("")m= 0For a in LT: If A.isdigit (): M=m+int (a)Print (m)* Solve the idea: get the numbers out of the string, separate the numbers from the other characters with if else, and format the other
Method Oneimport functoolssum = 0for i in range(1,21):sum = sum + functools.reduce(lambda x,y: x*y, range(1, i+1))print(sum)Lambda x,y:x*y means: There is a function that accepts X, y two parameters to do multiplication.import functoolsMethod Twodef f(n):if n == 1:return 1else:return functools.reduce(lambda x,y: x*y, range(1, n+1)) + f(n-1)print(f(20))Method Threedef plus(n):if n == 1:return 1else:return reduce(lambda x,y: x*y, range(1,n+1)) + plus(n-1)print plus(20)Method Foursum = 0x = 1for i
'], ['Little Red','Not delivered'], ['Little Green','Not delivered'], ['Xiao Huang','Not delivered'], ['Little Black','has been handed']]pass_list=[]#all the students who have handed in their homeworkFail_list=[]#students who do not hand in their homework forStuinchStus:status= Stu[1] Name=Stu[0]ifStatus = ='Not delivered': Fail_list.append (name)Else: Pass_list.append (name)Print('The student who has handed in the job is:%s, total%s personal'%(Pass_list,len (pass_list)))Print('non-han
'% (NUM1, num2, res))if choice = = ' 4 ':res=int (NUM1)/int (num2)print ('%s/%s=%s '% (num1,num2,res))#5, nested implementation based on for loop5.1 printing 99 multiplication TableFor i in range (1,10):For J in Range (1,i+1):print ('%s*%s=%s '% (j,i,i*j), end= ') #九成九法则print ()#5.2 Printing Pyramidsy = 5For x in range (1,y+1):For i in range (y-x):Print (', end= ') # Prints multiple spaces consecutively in a rowFor J in Range (2*x-1):print (' * ', end= ') #在一行中连续打印多个空格print ()print ('----------
]#your solution here forNameinchnames:ifLen (name) >Len (longest): Longest=name?Print(Longest)#Output ResultsJoshua ZhaoA singer of a singing contest scores, we design a program to help remove a minimum and a maximum score, and then calculate an average scoreFor example, the score is: [8,9,5,10,9.5,8,7,9,9.5] minus the lowest score [8,9,5,10,9.5,8,9,9.5]#idea: Traverse to find the minimum and maximum values respectively, then remove () and then divide the sum of the array by Len (values) .values
={3,2,5,8,4,15,14,1,25,6,3};maxmin (arr); System.out.println (); System.out.println (); SYSTEM.OUT.PRINTLN ("Hello! This is the result of selecting sorting "); XZPX (arr); System.out.println (); System.out.println (); SYSTEM.OUT.PRINTLN ("Hello! This is the result of the bubbling Sort "); MpPX (ARR1); System.out.println (); System.out.println (); SYSTEM.OUT.PRINTLN ("Hello! This is the result of a compromise choice of 1 "); zzpx (arr,30); System.out.println (); System.out.println (); SYST
Find the list of values greater than 100, give the dictionary dic's K1 key, less than or equal to 100 of the value, to the dictionary dic K2 key‘‘‘Tip: Two ways to create a dictionaryEx‘‘‘V1 = [2,3,4,5== = = {'K1'K2' = Dict (K1 = v1, K2 = v2,) Print (DIC1) Print (DIC2)List = [2, 5, 9, 20, 27, 80, 100, 110, 127, 158, 166, 198,]dic= {}#define an empty dictionary#method One:L1 = []#define two empty listsL2 = [] forIinchList#loop Find, traverse list element ifI > 100:#judging when the element val
overweight ."); } Else if(BMI >= - BMI *) {MessageBox.Show ("your index is"+ BMI +"\ n is obese ."); } Else if(BMI >= * BMI +) {MessageBox.Show ("your index is"+ BMI +"It's a severe obesity ."); } Else if(BMI >= +) {MessageBox.Show ("your index is"+ BMI +"It's a very heavy fat ."); }For loop additive 1 to N string n = console.readline (); int num = convert.toint32 (n);int sum=0; for (int i = 0; i ){sum = sum + i;// Long sum = num* (num + 1)/2;Console.WriteL
form details are displayed * Header *: Title/author/unit price/Quantity/Subtotal/operation foreach traverse the book cart.map1 in the shopping cart). * (javascript:void (0))--click event Deletitem (the ID of the Entry.key book passes through) By window.confirm to determine whether to delete, if the deletion is window.location.href=controllerservlet?id= ' "+id+" ", the request parameter type is DELETE2). (Quantity quantity can be entered manually---> Change event changequantity (this, book ID, n
Original: https://leetcode.com/problems/word-frequency/Write a bash script to calculate the frequency of each wordinchA textfilewords.txt.For simplicity sake, you could assume:words.txt contains only lowercase characters and space' 'characters. Each of the word must consist of lowercase characters only. Words is separated by one or Morewhitespace characters. For example, assume that words.txt have the following content:the day is sunny the thethe sunny are isyour script should out Put the follow
From exploit-exercises.comThe difficulty is lower, mainly is the debugging and programming in the skilled Linux environment.Stack01#include 2#include 3#include 4 5 intMainintargcChar**argv)6 {7 volatile intmodified;8 Charbuffer[ -];9 TenModified =0; One gets (buffer); A - if(Modified! =0) { -printf"You have changed the ' modified ' variable\n"); the}Else { -printf"Try again?\n"); - } -}View CodeCompile:Gcc-fno-stack-protector-z Execstack Stack1.c-o Stack1Solution:Simply overwrite the lo
/wKioL1djq4DjUi6rAABuyf0WTE8481.png "alt=" Wkiol1djq4djui6raabuyf0wte8481.png (566x365) "/>Fibonacci Sequence:#!/bin/basharry[0]=1arry[1]=2temp=0sum=0for i in {0..99}do if [$i-gt 0];thenletarry[$i +1]=arry[$i]+arry[$i-1] Fidoneecho ${arry[99]}Operation Result:650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/82/F2/wKiom1dmoqrj-0u3AAAM-HbKqwU568.png "title=" QQ picture 20160619163030.png "alt=" Wkiom1dmoqrj-0u3aaam-hbkqwu568.png "/>This article is from the "egg-left" blog, please be sure
Exercise one: Write a script 1. Set the value of the variable file to/etc/passwd 2. Say hello to each user in/etc/passwd, and say what the ID is like: (Hint: line= ' wc-l/etc/passwd|Cut-d ""-f1 ') Hello,root,your UID is 0. 3. Count the number of user programs that are as follows: #!/bin/bashfile= "/etc/passwd" line= ' wc-l $file |cut-d ""-f1 ' for I in ' seq 1 $line ';d ouserid= ' head-$i $file |Tail-1 |awk-f ":" ' {print $} ' username= ' head-$i $file | Tail-1 |awk-f ":" ' {print $} ' echo ' He
);
--Commit statement
2. Query statementsThe first step is to get the following result:Teacherid MONDAY Tuesday Wednesday Thursday FRIDAY--------- ---------- ---------- ---------- ---------- ----------1 0 1 0 0 01 0 0 1 0 02 1 0 0 0 03 0 1 0 0 01 0 1 0 0 0The query statements are: Select Teacherid, case if Weekday=1 then 1 else 0 end MONDAY, case when
weekday=2 then 1 Else 0 end Tuesday, case while weekday=3 then 1 else 0 end Wednesday, case when
weekday=4 then 1 Else 0 End thursday,In the
=/root/rsyncUse Chroot=trueMax Connections=4Read Only=noList=trueUid=rootGid=rootAuth Users=testSecrets file=/etc/rsyncd.passwd36.rsync synchronization, how to delete the target data more than the data, that the source does not exist, but the target exists in the file or directory?# Rsync-av--delete/test1//test2/37. When using free to view memory usage, which value represents the amount of memory actually available?Second line: value for free38. One day you suddenly find that the company's websi
has been learning, but also has been forgotten, today with the help of this blog post, to record their own learning process some of the most basic things!1. For#!/bin/bashfor i in {1..10}do echo $idoneScan the active IP in the target network segment#!/bin/bashfor IP in 192.168.1. {1..255};d oping $ip-C 2 >/dev/null, if [$?-eq 0];thenecho $ip is alivefidone2. If#!/bin/bash# determine if the current user is rootif [$UID-eq 0];thenecho You is root user.elseecho you are nothing.fiThis article is fro
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.